Seá*_*abe 6 jquery html5 attributes input
我有一个可以出现在不同页面上的表单,根据具体情况,并不总是需要这些字段.
我有隐藏div的代码,但不再需要输入字段.使用HTML5必需属性.无法使代码工作.代码如下:
$('#detailssame').click(function() {
if($(this).is(':checked')) {
$(\"#detailssamehide\").hide();
} else {
$(\"#detailssamehide\").show();
}
});
$('.fullboxform input[type=text], .fullboxform select').each(function() {
$(this).removeAttr('required');
});
Run Code Online (Sandbox Code Playgroud)
非常感谢所有帮助.
原来上面的代码确实可以正常工作,但使用prop可以选择其他答案
尝试使用prop()函数来设置HTML5属性.
$(function () {
$('#detailssame').click(function() {
var checked = $(this).is(':checked');
if(checked) {
$("#detailssamehide").hide();
} else {
$("#detailssamehide").show();
}
$('.fullboxform input[type=text], .fullboxform select').each(function() {
$(this).prop('required', !checked);
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12638 次 |
| 最近记录: |