PHP复选框获胜't撤消禁用属性,但将取消选中
PHP Checkboxes won't undo disable attribute, but will uncheck
我有几页长代码,但我很难让它发挥作用。下面的脚本在一个主复选框上使用onclick命令来检查和禁用具有特定ID的所有复选框。当用户取消单击该框时,复选标记将消失,但仍处于禁用状态。即使他们按下了重置按钮,禁用的盒子也会保留下来。
Javascript:
<script>
function checkAllbase(bx) {
var cbs = document.getElementsByTagName('input');
for(var i=0; i < cbs.length; i++) {
if(cbs[i].id == '1') {
cbs[i].checked = bx.checked;
cbs[i].disabled=true;
}
}
}
</script>
为每个与包关联的复选框输入提供类似的名称或类。在看不到实际html的情况下,在下方提供示例html
HTML
<input type="checkbox" class="package1" name="package1[]" value="vacation">
<input type="checkbox" class="package1" name="package1[]" value="bonus">
<input type="checkbox" class="package1" name="package1[]" value="fries">
JS-
function togglePackage(isChecked,packageName) {
//Choose one of the two below to use
//Below selects the inputs by the class name
var cbs = document.querySelectorAll("input."+packageName);
//Or Below selects the inputs by the input name
var cbs = document.querySelectorAll("input[name^="+packageName+"]");
for(var i=0; i<cbs.length; i++) {
//Since they are either checked and disabled (both true)
//or unchecked and enabled (both false) we can just use
//isChecked to set both at once.
cbs.checked = isChecked;
cbs.disabled = isChecked;
}
}
//Then somewhere call the togglePackage function
//bx here would be the main checkbox that you want to
//have toggling the other boxes, and "package1" is obviously
//the name or the class you gave the checkboxes.
togglePackage(bx.checked,"package1");
元素保持为disabled
,因为要设置的值是常量(文字)true
。
你可以做的是复制bx.disabled
,就像你在使用bx.checked
:一样
cbs[i].checked = bx.checked;
cbs[i].disabled = bx.disabled;
或者添加另一个参数以传递所需的disabled
状态:
function checkAllbase(bx, disabled) {
disabled = disabled !== false; // limit to `true` or `false`, prefer `true`
// ...
cbs[i].checked = bx.checked;
cbs[i].disabled = disabled;
// ...
}
// usage
checkAllbase(bx); // disables elements
checkAllbase(bx, true); // also disables elements
checkAllbase(bx, false); // enabled elements
相关文章:
- 取消img的css属性宽度和高度(不能使用“auto”)
- 取消 iframe 中具有 target=“_parent” 属性的链接事件
- 取消绑定angular中的scope属性
- GWT:setInnerHTML取消映射属性值
- 使用构造函数创建的数字没有其值作为属性,请取消String与构造函数的链接
- 如何将数组取消移动到对象的每个属性中
- 按钮输入上的 CSS 取消了 jQuery 中禁用的 prop 属性
- JSON 序列化 - 如何取消属性值的引号
- PHP复选框获胜't撤消禁用属性,但将取消选中
- 当getElementById返回null时,取消对属性/方法的访问
- 取消设置对象属性
- 如何在规范化/取消规范化属性名称之前获取原始属性名称
- 取消属性值的规范化-将基于骆驼的值转换为以短划线分隔的值
- 使用Breeze.js取消订阅所有属性更改事件
- Ajax Post在onclick属性中被取消
- 取消设置以相同子字符串开头的Backbone.js模型的所有属性
- 如何删除/取消设置JavaScript对象的属性
- <输入类型=“文件” /单击“取消”时>更改属性
- 取消选中使用 JavaScript 中的数据属性复选框
- AngularJS:使用timeout属性取消$http请求