[英]jQuery add attribute with backslash
I am trying to add the input dynamically, with custom html5 validation. 我试图动态添加输入,使用自定义html5验证。 The jQuery code is as below. jQuery代码如下。
$('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\d*" title="Please Enter Valid No.">');
but in html output looks like this: 但在html输出中看起来像这样:
<input type="text" name="test_input" id="test_input" required pattern="d*" title="Please Enter Valid No.">
instead of \\d*
it is coming d*
. 而不是\\d*
它来了d*
。
Escape the slash \\
: 逃避斜线\\
:
$('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\\d*" title="Please Enter Valid No.">');
or you can also write character code for \\
ie, \
或者您也可以为\\
ie, \
编写字符代码\
like: 喜欢:
$('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\d*" title="Please Enter Valid No.">');
与转义字符一起使用即\\
$('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\\d*" title="Please Enter Valid No.">');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.