gpt4 book ai didi

javascript - 根据先前的输入选项选择(单选按钮)显示 div 的内容。在一个文件中工作,而不是在其他文件中工作

转载 作者:行者123 更新时间:2023-11-28 09:38:59 25 4
gpt4 key购买 nike

我有一个两步表单。第一步提出一个问题并有 3 个单选按钮。

根据选择的单选按钮,第二步通过“取消隐藏”一个 div 来显示答案。

例如第 1 步:你选择什么选项?选项1,选项 2,选项 3

第 2 步:有3个隐藏的div,根据步骤1中的选项,其中一个从display:none改为display:block并显示。

这是我的代码:

$(document).ready(function () {
$("input[rel$='lastq']").click(function () {
var value = $(this).val();
if (value == 'last1') {
$(".thank1").show();
$(".thank2").hide();
$(".thank3").hide();
}
else if (value == 'last2') {
$(".thank2").show();
$(".thank1").hide();
$(".thank3").hide();
}
else if (value == 'last3') {
$(".thank3").show();
$(".thank1").hide();
$(".thank2").hide();
}
else {
$(".thank1").hide();
$(".thank2").hide();
$(".thank3").hide();
}
});
$(".thank1").hide();
$(".thank2").hide();
$(".thank3").hide();
});

我的 html 是:

<input type="radio" rel="lastq" name="" value="last1" id="" /> Option 1
<input type="radio" rel="lastq" name="" value="last2" id="" /> Option 2
<input type="radio" rel="lastq" name="" value="last3" id="" /> Option 3

<div class="thank1">thank you 1</div>
<div class="thank2">thank you 2</div>
<div class="thank3">thank you 3</div>

现在奇怪的是这对单个文件(本地)工作正常,显示正确的“谢谢”div。但是当我在我的一个元素(在本地机器上使用 wordpress)中(再次在本地)使用它时,它不起作用。

观察到的问题:

1) 当它工作时,“thank you div”默认为 style="display:none;"

2) 但在元素中使用时,当不工作时,thank you div 没有分配显示:无。

这可能是什么原因造成的?为什么它没有在元素中分配,但仍在独立文件中工作?

最佳答案

通过在脚本代码的顶部添加 $ = jquery.noconflict() 解决了问题。

jquery 加载正常,但它一定与其他脚本有冲突吗?

无论如何,对于后来来这里的任何人来说问题都解决了......

关于javascript - 根据先前的输入选项选择(单选按钮)显示 div 的内容。在一个文件中工作,而不是在其他文件中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25450275/

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