简体   繁体   English

多个选择框中的jQuery optgroup和选项值

[英]jQuery optgroup and option value in multiple select box

Please refer to my first question by this link , thanks to @AV for helpfulness, 请通过此链接引用我的第一个问题,感谢@AV的帮助,

The script which provided is work great in fact, but there is an issue in the giving name for option value and optgroup , please go http://jsfiddle.net/NZ6tY/7/ for more specific action, group 1-1 is working nice with option value and optgroup label without space , comma or slash , where the rest is unworkable, can anyone please give a solution? 提供的脚本实际上效果很好,但是option valueoptgroup名称存在问题,请转到http://jsfiddle.net/NZ6tY/7/以获取更多具体操作, 第1-1组正在工作选项值和optgroup标签很好,没有空格逗号斜杠 ,其余都不可行,有人可以提供解决方案吗? I must having a long text in the option value and optgroup label as necessary info. 我必须在选项值和optgroup标签中加长文本作为必要的信息。

Thanks. 谢谢。

Referencing your jsfiddle, the problem with it is the selector for the optgroup. 引用您的jsfiddle,问题在于optgroup的选择器。

It currently looks like this: 当前看起来像这样:

$('optgroup[label='+somelabel+']');

Which does work fine, however when somelabel contains spaces or special characters, they interfere with the selector. 确实可以,但是当somelabel包含空格或特殊字符时,它们会干扰选择器。 To remedy this, simply enclose somelabel with quotes, like this: 为了解决这个问题,只需将somelabel用引号引起来,例如:

$('optgroup[label="'+somelabel+'"]');

I forked your fiddle and made the update (line 33): http://jsfiddle.net/S7NkB/ 我分叉了您的小提琴并进行了更新(第33行): http : //jsfiddle.net/S7NkB/

Edit: please note that if somelabel contains quote characters you would want to escape or replace those or it will break again. 编辑:请注意,如果somelabel包含引号字符,则您要转义或替换这些引号字符,否则它将再次中断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM