作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 JavaScript 函数:
function someAction(thisTd,text){
alert(text);
thisTd.innerHTML=text;
...
}
和 html 文件:
<td onclick="someAction(this,<?echo 'Long-long text with <b>html-formatting</b>'?>)"/>
当我使用这样的代码函数 someAction 不会调用(因为警报没有显示)并且在 Opera 的错误控制台中没有显示错误。如何解决这个问题?
附:我不使用框架(JQuery 等)。
更新#1
当我使用这样的代码时:
<?$encoded=str_replace("\n","",str_replace("\r\n","",$text));echo $encoded?>
效果很好。但我不确定它在 Linux 中是否正常工作。(我使用 Windows)
最佳答案
确保您HTML encode它并在参数两边加上单引号:
<td onclick="someAction(this, '<?echo htmlspecialchars('Long-long text with <b>html-formatting</b>', ENT_QUOTES) ?>')"/>
关于javascript - 如何将长值传递给javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3984778/
我是一名优秀的程序员,十分优秀!