具有双引号问题的动态输入名称 [英] Dynamic input name with double quotes issue
本文介绍了具有双引号问题的动态输入名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
方案:当< div>
文本具有双引号。 JQuery方法附加动态输入并提醒输入的值不起作用。当转义引号时,我知道这个问题触发。有人可以查看代码?
Scenario : When <div>
text has double quote. JQuery method to append dynamic input and to alert the value of input is not working. I know this issue trigger when escaping quotes. Can someone review the code?
var divText = $("div").text();
$('form:not(:has([name="' + divText + '"]))').append($('<input>', {
type: 'text',
value: divText,
name: divText
}));
alert($('[name="' + divText + '"]').val());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>"</div>
<form>
</form>
我在这里创建了一些演示
推荐答案
如果您必须使用双引号,可以像这样删除:
If you must use double quotes, you can remove them like so:
var divText = $("div").text().replace(/"/g, '');
这篇关于具有双引号问题的动态输入名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文