gpt4 book ai didi

javascript - 按名称在 html 代码中搜索元素

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

我尝试使用 javascript 在 html 代码中搜索名为 range 的元素。之后,它应该显示一个带有该元素值的警报框。

if($('[name=scope]').length > 0){
var scope = $(this).value();

alert(scope);
}

但这对我不起作用。我可以做什么来解决这个问题?

谢谢!

最佳答案

你需要val()而不是value(),jQuery中没有值函数

var scope = $(this).val();

或者直接使用this.value,这样会更简单、更快

var scope = this.value;

根据评论进行编辑

$('[name=scope]').each(function(){
alert(this.value);
});

关于javascript - 按名称在 html 代码中搜索元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33166911/

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