gpt4 book ai didi

javascript - 每个()中的索引值相同

转载 作者:行者123 更新时间:2023-11-28 15:35:30 25 4
gpt4 key购买 nike

我正在编写一个脚本,它将自动用其索引值填充输入项。

到目前为止我已经写了这个:

$('body').append($("<input>", {type: "button", id: "numeruj", value: "Numeruj"}));
var $numery = $('input[id*="FileDescriptionTextBox"]');


$("#numeruj").click(function(){
$numery.each(function(index){
$numery.val(index)
})
})

问题是每个项目都被分配了相同的索引值,基本上是 $numery.length。我不明白为什么每个项目没有分配自己的索引。谁能指出我正确的方向吗?

最佳答案

您需要在每个 block 内使用$(this)。关键字 this 引用元素

使用

$("#numeruj").click(function() {
$numery.each(function(index) {
$(this).val(index); //You need to use this
})
})

关于javascript - 每个()中的索引值相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25740346/

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