我需要创建一个jQuery选择器来查找没有类"clear"的所有输入,使其值大写.
目前我有这个代码:
$("form").submit(function () {
$("input[type=text]").val(function () {
if (!$(this).hasClass("clear")) {
return this.value.toUpperCase();
} else {
return this.value;
}
});
$("input[type=text].lower").val(function () {
return this.value.toLowerCase();
});
});
Run Code Online (Sandbox Code Playgroud)
这段代码运行良好,但如果我只使用选择器,我可以跳过if/else代码.我搜索过这个选择器,但没有成功.
任何的想法?
最终守则
我的最终代码如下所示:
$("form").submit(function () {
$("input[type=text]").not(".clear").not(".lower").val(function () {
return this.value.toUpperCase();
});
$("input[type=text].lower").val(function () {
return this.value.toLowerCase();
});
});
Run Code Online (Sandbox Code Playgroud)
感谢所有回复.
使用:不是()
$("input[type=text]:not(.clear)").val(function () {
return this.value.toUpperCase();
});
Run Code Online (Sandbox Code Playgroud)
使用.not()
$("input[type=text]").not("YOUR_CLASS").val(function () {
return this.value.toUpperCase();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
442 次 |
| 最近记录: |