jQuery selector with ids and comma

后端 未结 4 1119
臣服心动
臣服心动 2021-01-12 19:08

I am using MyTableGrid to show an Excel like control in my webpage.

The cells are referenced with ids like \"mtgIC1_0,2\" for table 1, column 0, row 2.

Unfor

相关标签:
4条回答
  • 2021-01-12 19:36

    If you have known coordinates of the table, you can target the cell like this:

    $('#myTable tr:nth-child(2) td:nth-child(2)').css('background-color', '#F00');
    
    0 讨论(0)
  • 2021-01-12 19:37

    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

    e.g

    $('#mtgIC1_0\\,2')
    
    0 讨论(0)
  • 2021-01-12 19:37

    I don't know offhand if this is the reason, but according to here, ID names should not contain commas. The relevant sentence is:

    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 (".").

    0 讨论(0)
  • 2021-01-12 19:52

    From here http://api.jquery.com/category/selectors/

    "If you wish to use any of the meta-characters (#;&,.+*~':"!^$[]()=>|/ ) as a literal part of a name, you must escape the character with two backslashes: \\. For example, if you have an an input with name="names[]", you can use the selector $("input[name=names\\[\\]]")."

    0 讨论(0)
提交回复
热议问题