gpt4 book ai didi

javascript - jquery动态下拉列表

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

我有这个脚本:

jQuery(document).ready(function($){

$('#website').change(function() {

$.get('inc/dropdown.php',{id: $(this).val() },function(d){
$('#loc').replaceWith(d);
});
});
});

将此 HTML 放在第一个下拉列表中。

<label for="website"><strong>Web Site:</strong></label>
<?php inc dynamic form ?>

这会被动态下拉菜单取代。

 <span id="loc">Please select an option from above.</span>

我遇到的问题是,当我在“网站”下拉列表中的项目之间单击时,它不会更新其他下拉列表。它会粘在第一个被点击的地方。

最佳答案

The issue I am having is that when I click between the items in the Web Site dropdown it doesn't update the other dropdown

其他下拉菜单是什么意思?此处您使用的是 ID,因此您不能使用相同的脚本来创建其他下拉列表。如果您需要此代码可供不同元素使用,您应该考虑使用类。

此外,您使用 .replaceWith 而不是 .text,替换 DOM 元素时应使用 .replaceWith,这就是您的意图?

关于javascript - jquery动态下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16804299/

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