gpt4 book ai didi

javascript - 向 JavaScript 函数发送参数时替换双引号

转载 作者:行者123 更新时间:2023-11-28 19:39:27 25 4
gpt4 key购买 nike

这是 JSFiddle :

http://jsfiddle.net/5kdek3vn/

我有如下按钮:

<button class="buttoncss" title="Modify This Artifact File" onclick="setFileDescriptionForUpdate('!@#$%^&amp;*()_+-=~`{}|[]\:" ;'&lt;&gt;?,.="" ','state.dat','167','1','c:\\pp_artifactsuploadedfiles\evalid_318\state.dat');">Modify</button>

在此单击中,我正在调用 setFileDescriptionForUpdate 函数,其第一个参数是字符串,如下所示:

!@#$%^&*()_+-=~`{}|[]\:";'<>?,./

当字符串中包含“时,就会产生问题。

我可以做出哪些改变来避免这种情况?

请帮助我。

最佳答案

如果内联,则需要 HTML 转义

如果你必须在 html 中使用内联 javascript,那么你必须转义它

& becomes &amp;
< becomes &lt;
> becomes &gt;

在属性值中,您还必须转义引号字符 [spec]:

" becomes &quot;
' becomes &#39;

关于javascript - 向 JavaScript 函数发送参数时替换双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357876/

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