gpt4 book ai didi

javascript - 如果 id 中的最后一个数字小于 i,则显示元素

转载 作者:行者123 更新时间:2023-11-30 18:03:56 26 4
gpt4 key购买 nike

我有名为 id="tag1"、id="tag2"等的 span 元素,我只想.show() id 中最后一个数字较小的 span比例如。 19.
这些元素属于一个 class="notVis",当页面首次加载时是 $(".notVis").hide();

我对此和自学完全陌生,这就是为什么下面尝试的代码会产生很多笑声,我敢肯定。感谢您的帮助!

var iMax = 19;
var i = 3;
var field = "tag" + i;
while(i < iMax){
$("#field").show(); i = i + 1; field = "tag" + i;
}

最佳答案

您需要在选择器中替换“字段”的值:

$("#" + field).show();

JavaScript 没有任何将动态值插入字符串的内置机制,但其他一些语言有。

关于javascript - 如果 id 中的最后一个数字小于 i,则显示元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16263848/

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