2 回答

TA贡献1765条经验 获得超5个赞
您没有正确连接字符串。解决替换这条线
echo "<button onclick=\"view_notes($js_notes)\">View Notes</button>";
和
echo "<button onclick='view_notes(".$js_notes.")'>View Notes</button>";
要解决换行问题,请再创建一个 javascript 函数
function nl2br (str, is_xhtml) {
if (typeof str === 'undefined' || str === null) {
return '';
}
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
并像这样在 view_notes 函数中使用上述函数
function view_notes(notes) {
var myWindow = window.open("", "MsgWindow", "width=400,height=400");
console.log(notes);
myWindow.document.write(nl2br(notes));
}

TA贡献1942条经验 获得超3个赞
你能分享console.log(notes)的结果吗?
因为我认为问题是这里的引号不匹配 - echo "View Notes"; 当它评估它时,它会将 $js_notes 放在双引号中,这会破坏 HTML 语法规则。
在浏览器中查看页面的源代码并检查这一行。
希望这会有所帮助。
- 2 回答
- 0 关注
- 176 浏览
添加回答
举报