gpt4 book ai didi

jquery - jquery .after 在这种情况下应该如何工作?

转载 作者:行者123 更新时间:2023-12-01 02:57:07 25 4
gpt4 key购买 nike

我不知道我是否错误地使用了 .after,但我的理解是它应该在我指定的元素之后显示元素? - Option1 选择后的 hello world 选择框?

<select id="cselect" >
<option value="Option 1">Option 1</option>

</select>

$('#cselect').chosen();

var test = '<select id="dselect" ><option>Hello World</option></select>';

$('#cselect').after(test);

$('#dselect').chosen();

在这里摆弄 - http://jsfiddle.net/jHvmg/4/

我错过了什么? TIA

最佳答案

这与所选插件有关。当您第一次在第一个 select 上调用 chosen 时,您最终会得到以下结果(伪代码):

<select id="select1"></select>
<div id="chosenForSelect1"></div>

附加新的选择后,您将得到以下内容:

<select id="select1"></select>
<select id="select2"></select>
<div id="chosenForSelect1"></div>

然后在第二个 select 上调用 .chosen() 并最终得到以下结果:

<select id="select1"></select>
<select id="select2"></select>
<div id="chosenForSelect2"></div>
<div id="chosenForSelect1"></div>

因此,实际的 select 元素是在第一个元素之后添加的,但支持所选插件的 div 却出现了问题。最好将新的 select 附加到容器,为每个 select 添加一个容器,或者附加在所选插件的 html 之后。

关于jquery - jquery .after 在这种情况下应该如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18748075/

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