gpt4 book ai didi

jquery - $ ("input:not(:empty)") 不工作

转载 作者:行者123 更新时间:2023-12-03 22:00:06 25 4
gpt4 key购买 nike

<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert('hi'+$("input:text").val());
$("input:not(:empty)").val("sdfdf");
});
});
</script>
</head>
<body>
<input type="text" value="aa" />
<input type="text" value="" />
<input type="text" value="aa" />
<button>Click me</button>
</body>
</html>

我正在尝试使用jquery访问空textboxex并为其分配一个值hello..但它不起作用。

提前致谢

最佳答案

:empty检查元素是否有子元素。 input 元素不能有子元素。

如果您想测试 input 元素的值为空:

$(document).ready(function(){
$("button").click(function(){
$("input").filter(function() {
return this.value.length !== 0;
}).val("sdfdf");
});
});

在那里,我们获取所有 input 元素,然后对其进行过滤,以便只有 value 属性不是 "" 的元素包括在内。

关于jquery - $ ("input:not(:empty)") 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9173533/

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