方括号表示字符串不起作用 [英] Square brackets meaning string wont work
问题描述
我有点困惑,尝试使用此jquery行将select选项的结果输入文本区域
I am a bit stuck, trying to use this jquery line to enter a result from a select option into a text area
这不起作用
$("#id[txt_17]").val($(this).find("option:selected").attr("name"));
这样做
$("#idtxt_17").val($(this).find("option:selected").attr("name"));
[]是通过oscommerce插件编码的,我不知道它们的重要性,或者我将其删除会做什么,但我想知道是否有解决方法,可以将其保留.创建了一个引用id的变量,但是由于方括号,它仍然无法正常工作.
The [ ] are coded in via an oscommerce plugin and I have no idea of the importance of them, or what me removing them would do, but I am wondering if there is a workaround so I can leave them in. I tried creating a variable referencing the id but it still didnt work because of the square brackets.
任何帮助将不胜感激.
Thx
推荐答案
请参阅: jQuery-类别:选择器
使用任何元字符(例如 !#$%&'((*),+/.;< =>?@ [] ^`{|}〜)作为名称的文字部分,必须 用两个反斜杠转义:\.例如,具有 id ="foo.bar",可以使用选择器$(#foo \ .bar"). W3C CSS 规范包含有关有效CSS的完整规则集 选择器. Mathias Bynens在CSS上的博客条目也很有用 标识符的字符转义序列.
To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \. For example, an element with id="foo.bar", can use the selector $("#foo\.bar"). The W3C CSS specification contains the complete set of rules regarding valid CSS selectors. Also useful is the blog entry by Mathias Bynens on CSS character escape sequences for identifiers.
替换:
$("#id[txt_17]").val
具有:
$("#id\\[txt_17\\]").val
这篇关于方括号表示字符串不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!