我在包含分号的输入框中有一个id。如何选择此元素?
<input type="text" title="City" name="billing[city]" value="" class="input-text required-entry" id="billing:city">
答案 0 :(得分:1)
在jQuery 3.0中引入了jQuery.escapeSelector():
转义任何在CSS选择器中具有特殊含义的字符。
var eleSelector = '#' + $.escapeSelector( "billing:city");
// with an older jQuery version
//var eleSelector = '#billing\\:city";
console.log('eleSelector: ' + eleSelector);
console.log($(eleSelector).get(0).outerHTML);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" title="City" name="billing[city]" value="" class="input-text required-entry" id="billing:city">
&#13;
答案 1 :(得分:1)
您可以将元素设为:
var elem = $("input[id='billing:city']");