具有ID和逗号的jQuery选择器 [英] jQuery selector with ids and comma
问题描述
我正在使用 MyTableGrid 在我的网页中显示类似Excel的控件.
I am using MyTableGrid to show an Excel like control in my webpage.
表1的第0列,第2行的单元格引用的ID如"mtgIC1_0,2".
The cells are referenced with ids like "mtgIC1_0,2" for table 1, column 0, row 2.
不幸的是,当我尝试使用ID为$("#mtgIC1_0,2")
的jQuery选择器时,它永远无法工作.
Unfortunately, when I try to use the jQuery selector with this id $("#mtgIC1_0,2")
, it never works.
我认为这是因为出现了,",因为它适用于页面中的其他所有ID,而不会出现昏迷.
I figured it is because of the "," since it works for any other ids in the page without coma.
推荐答案
ID和NAME令牌必须以 字母([A-Za-z]),并且可以紧随其后 用任意数量的字母,数字 ([0-9]),连字符(-"),下划线 ("_"),冒号(:")和句点(.")
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
但是,如果您转义了逗号,它仍然可以正常工作
However if you escape the comma it should still work
例如
$('#mtgIC1_0\\,2')
这篇关于具有ID和逗号的jQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!