jQuery使用反斜杠添加属性
我试图通过自定义html5验证动态添加输入。jQuery代码如下所示jQuery使用反斜杠添加属性,jquery,Jquery,我试图通过自定义html5验证动态添加输入。jQuery代码如下所示 $('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\d*" title="Please Enter Valid No.">'); $('#test').html(''); 但在html中,输出如下所示: <input type="text" name="test_input" id
$('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\d*" title="Please Enter Valid No.">');
$('#test').html('');
但在html中,输出如下所示:
<input type="text" name="test_input" id="test_input" required pattern="d*" title="Please Enter Valid No.">
而不是
\d*
它来了d*
转义斜杠\
:
$('#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.">');
$('#test').html('');
只需使用双精度\\
$('#test').html('<input type="text" name="test_input" id="test_input" required pattern="\\d*" title="Please Enter Valid No.">');