gpt4 book ai didi

javascript - 使用 HTML 实体设置元素值

转载 作者:行者123 更新时间:2023-11-28 18:29:46 25 4
gpt4 key购买 nike

我在使用 HTML 实体时尝试设置输入字段的值时遇到问题,因为它们实际上是 " 而不是 "

这是我正在使用的代码:

document.getElementById('inputSurname').setAttribute('value', 'test"""');

其中输出为 test""",但我希望输出为 test"""

它看起来不像是双重编码问题,因为在源代码中我看到它的方式与我在此处设置它的方式相同。

我知道我可以从 HTML 实体格式中解码该值,尽管为了安全起见,我想避免这种情况。

任何帮助将不胜感激:)

最佳答案

试试这个:

document.getElementById('inputSurname').value = 'test"""';

或者如果您想保留“:

function myFunction() {
document.getElementById('myText').value = replaceQuot('test&quot&quot&quot');
}
function replaceQuot(string){
return string.replace('&quot', '""');
}

关于javascript - 使用 HTML 实体设置元素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38308752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com