gpt4 book ai didi

jquery - 如何使用 :input in jquery? 排除只读字段

转载 作者:行者123 更新时间:2023-12-03 22:56:40 26 4
gpt4 key购买 nike

到目前为止,我只使用了一些基本的 jquery 选择器和函数。但我正在看这个clear form function我不知道如何添加它,以便我可以删除隐藏输入和只读输入以防止清除。

有人可以帮忙吗?谢谢。

function clearForm(form) {
// iterate over all of the inputs for the form
// element that was passed in
$(':input', form).each(function() {
var type = this.type;
var tag = this.tagName.toLowerCase(); // normalize case
// it's ok to reset the value attr of text inputs,
// password inputs, and textareas
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = "";
// checkboxes and radios need to have their checked state cleared
// but should *not* have their 'value' changed
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
// select elements need to have their 'selectedIndex' property set to -1
// (this works for both single and multiple select elements)
else if (tag == 'select')
this.selectedIndex = -1;
});
};

最佳答案

如果元素的声明中有 readonly 属性,则可以使用 jQuery’s :not() selector :

$(':input:not([readonly])', form)

否则,使用如下内容过滤只读元素:

$(':input', form).each(function() {
if (this.readOnly) return;
// …
});

关于jquery - 如何使用 :input in jquery? 排除只读字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2617065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com