duanpo7796 2017-08-28 18:15
浏览 45

如果存在数据,如何在复选框上创建持久性功能

I have seen many checkbox examples, but not this one.

I need a checkbox to remain checked if data is present in specific <input> fields. So it would need to be something that is constantly checking field status.

Basic checkbox:

<input class="checkbox" type="checkbox" unchecked onclick="shipping()"/>

It calls a function that removes a <div> and adds a shipping info page. There is a back button there that will remove shipping page and add orig. If they entered shipping data I want that checkbox to be checked. Now if they click it again, the data they entered on the shipping page would disappear. And process can be repeated.

This is a PHP page so I am comfortable using javascript, jQuery or PHP. Just looking for the most reliable way.

  • 写回答

1条回答 默认 最新

  • douhuangjian9627 2017-08-28 18:22
    关注

    JavaScript is the way to go because PHP can't react to what's happening in the browser. I would register an onchange event handler to the input that drives the checkbox. When the input is altered (ie when the handler is triggered):

    1. Read the value, and if it is empty then...
    2. Enable the checkbox.
    3. Else, disable the checkbox and set it as checked

    This should prevent a user of the UI from unchecking the box while there is content in the input

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题