总有人间一两风,填我十万八千梦

jQuery .escapeSelector() 用法 手册 | 示例代码

jQuery开发手册 归档 202℃ 0评论

Description: Escapes any character that has a special meaning in a CSS selector.

  • version added: 3.0jQuery.escapeSelector( selector )

    • selector
      Type: Selector
      A string containing a selector expression to escape.

This method is useful for situations where a class name or an ID contains characters that have a special meaning in CSS, such as the dot or the semicolon.

The method is essentially a shim for the CSS Working Group's CSS.escape() method. The main difference is that $.escapeSelector() can be reliably used in all of jQuery's supported browsers.

Examples:

Escape an ID containing a hash.

1
$.escapeSelector( "#target" ); // "#target"

Select all the elements having a class name of .box inside a div.

1
$( "div" ).find( "." + $.escapeSelector( ".box" ) );

转载请注明:悠然品鉴 » jQuery .escapeSelector() 用法 手册 | 示例代码

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址