gpt4 book ai didi

javascript - 使用 jquery 替换复选框列表中的标签

转载 作者:行者123 更新时间:2023-11-28 05:49:39 25 4
gpt4 key购买 nike

我正在尝试使用 jquery 用超链接替换标签。但是它对我不起作用。我希望每个列表项都有一个基于其值的特定超链接。这是我尝试过的..jQuery 代码:

        $('.chkList li label').each(function () {

if ($(this).val() == "1")
$this.replaceWith('<a href="">link 1</a>');
if($(this).val() == "2")
$this.replaceWith('<a href="">link 2</a>');
});

asp.net 代码:

 <asp:CheckBoxList ID="chkList" runat="server" RepeatLayout="UnorderedList" CssClass="chkList">
<asp:ListItem Text="A" Value="1"></asp:ListItem>
<asp:ListItem Text="B" Value="2"></asp:ListItem>
<asp:ListItem Text="C" Value="3"></asp:ListItem>
</asp:CheckBoxList>

我在这里缺少什么?

最佳答案

好吧 - 有两件事 A)您对 $this 的使用需要像评论中那样进行更改,但我也刚刚意识到您正在比较该值。所有输入值都是字符串,直到转换为数字,因此可以使用 parseInt() 进行转换:

 if (parseInt($(this).val())== 1)

或将其保留为字符串

 if ($(this).val() == "1")

关于javascript - 使用 jquery 替换复选框列表中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38181404/

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