Jquery,链接动态添加的选择
我在使用 这个 与 select
配合使用的 jQuery 插件时遇到问题s。
这里是我的 HTML 和 Javascript 代码。它有点大,主要是因为 select
中有很多 option
。
一开始它工作得很好——它成功地复制了目标元素。但在那之后,它就停止工作了。
我已经尝试修复它两天了,但不知道该怎么办。我警告
插件中的所有变量,发现备份变量没有正确的数据,并且当它使用#location[2]
创建元素时它还调用 #location[1]
的插件。
更好地描述问题 我对 fe 进行了三个选择:品牌、型号、颜色,
假设值可以是:
品牌: Iphone、Nokia; 适用型号: 4s,5800; 颜色:黑色、白色、蓝色、红色
,并且应该只有这些选项:
Iphone -> 4s->黑/白
诺基亚-> 5800——>蓝色/红色,
所以当我选择诺基亚时 -> 5800,我不想显示“白色”或“黑色”选项。
我为此使用了 jQuery 插件(我在上面链接了它),它工作得很好。
问题是: 我有一个按钮可以添加另一行该选择,并且该插件在插入多行后停止工作。我知道问题出在带有变量 backup 的插件中,
谁能告诉我是什么原因导致了这个问题吗?
I'm having a problem with this jQuery plugin that works with select
s.
Here's my HTML and Javascript code. It's a bit large, primarily because of the many option
s in the select
.
It works fine at first—it successfully copies the target elements. But after that, it stops working.
I've been trying to fix it for two days and don't know what to do. I was alert
ing all the variables in the plugin and found out that the backup variable doesn't have the right data and when it creates the element with #location[2]
it also calls the plugin for #location[1]
.
Better description of problem
I had a three selects with f.e.: brand, model, color
lets say the values could be:
for brand: Iphone, Nokia;
for model: 4s, 5800;
for color: black, white, blue, red
and there' should be only these options:
Iphone -> 4s -> black / white
Nokia -> 5800 -> blue / red
so when I select nokia -> 5800, I didnt want an option "white" or "black" to be shown.
I used jQuery plugin (I linked it above) for this, and it works fine.
The problem is:
I have there a button to add another row of this selects and this plugin just stops working after inserting multiple rows. I know the problem is in plugin with variable backup
Can anyone tell what is causing the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何对此类有疑问的人,我以这种方式修复了它:
我使用
$().clone()
为每个选择创建了(备份)副本。然后在插入另一行选择后,我保存到$(".select_to_be_chained").data("original_ref", $(".copy") )
对该选择副本的引用,然后将其链接起来。要实现此功能,您必须编辑 jquery.chained.js:
找到:
$(self).html(backup.html());
将其替换为:
使用示例
我还没有测试过这个示例,但它知道了我如何使用它以及它的工作原理,我希望每个需要它的人都能理解它:)
For anybody that have a trouble with this class, I fixed it this way:
I made a (backup) copy of every select with
$().clone()
. Then after inserting another row of selects, I saved to$(".select_to_be_chained").data("original_ref", $(".copy") )
reference to that copy of select and than chained it.To make this work, you have to edit your jquery.chained.js:
find this:
$(self).html(backup.html());
replace it with:
USAGE EXAMPLE
I haven't tested the example, but it got the idea how I use it and it works, I hope everybody that gonna need it will understand it :)