zoukankan      html  css  js  c++  java
  • Jquery选择器特殊字符问题

    场景: $("#" + AAA + ""),AAA代表某表单ID

    当AAA为普通字符串时,ok;

    当AAA含有特殊符号时(eg:a.b),获取不到该对象;

    原因:特殊符号会进行转义,上面那种方式就无法获取的该ID。

    // Does not work:
    $( "#some:id" )
    // Works!
    $( "#some\:id" )
    // Does not work:
    $( "#some.id" )
    // Works!
    $( "#some\.id" )

    解决:
    The following function takes care of escaping these characters and places a "#" at the beginning of the ID string:
    function jq( myid ) {
    return "#" + myid.replace( /(:|.|[|]|,)/g, "\$1" );
    }
    The function can be used like so:
    $( jq( "some.id" ) )
     
     
    http://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/
  • 相关阅读:
    Sql server数据库设计 7
    day08作业
    day01作业
    day07作业.
    day05作业
    day04作业
    day02作业
    初学Java的一些注意事项
    day07作业
    Week03面向对象入门
  • 原文地址:https://www.cnblogs.com/zhilianghunag/p/5459452.html
Copyright © 2011-2022 走看看