我从 json
得到烦人的双引号当我转换 html
至 json
友好。
在<p>"
开头的代码中可以看到&结束"<\p>
.我怎样才能删除它们。试过以下不起作用。
$("p").html().replace(/['"]+/g, '')
这是 js 变量中的动态 html。
<p>"<!--HTML icon appears here--><a href="https://www.example.com/viewer/event.jsp?ei=1434586&tp_key=e8ced8705c" target="_blank">Click here for web</a><br>
<!--PDF icon appears here--><a href="../file/408427349/Index?KeyFile=1500113055" target="_blank">Press Release</a><br>
<!--PDF icon appears here--><a href="../file/4234/Index?KeyFile=234324" target="_blank">somelink</a><br>"</p>
最佳答案
清理完文本后,您是否忘记设置 html?
应该这样做:
var text = $('p').html().replace(/['"]+/g, '')
$('p').html(text)
// or you can just:
// $('p').html($('p').html().replace(/['"]+/g, ''))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>"<!--HTML icon appears here--><a href="https://event.web.com/viewer/event.jsp?ei=1434586&tp_key=e8ced8705c" target="_blank">Click here for web</a><br>
<!--PDF icon appears here--><a href="../file/408427349/Index?KeyFile=1500113055" target="_blank">Press Release</a><br>
<!--PDF icon appears here--><a href="../file/4234/Index?KeyFile=234324" target="_blank">somelink</a><br>"</p>
关于javascript - 从 HTML 中删除恼人的双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52658536/