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

    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗