js拼接html注意问题示例探讨

前端技术 2023/09/04 JavaScript

你想让别人给你解决什么,
adress是什么,

var hrf=\'<a href=\"javascript:;\" rel=\"external nofollow\" rel=\"external nofollow\" onclick=\"window.open(\'+url+\',\'\',\'\"height=625,width=830,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no\"\')\">\'+adress+\'</a>\';

下面又出现adress[j]。用法完全不对。

msg+=\'<tr style=\"height:25px\"><td align =\"left\" style=\"width:6%;color:Black\">\'+coal[j]+\'</td><td align =\"left\" style=\"width:8%;color:Black\">\'+url+hrf+\'</td><td align =\"left\" style=\"width:24%;color:Black\">\'+adress[j]+\'</td><td align =\"left\" style=\"width:12%;color:Green;font-weight :bold\">\'+ssz[j]+\'</td>\';

追问

我是想把

<a href=\"javascript:;\" rel=\"external nofollow\" rel=\"external nofollow\" onclick=\"window.open(\'+url+\',\'\',\'\"height=625,width=830,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no\"\')\">\'+adress+\'</a>

这句外面加个单引号,可是试了好多次都不成功,这句话加上单引号,里面改怎么变化呢

回答

用转义符, \\\" = \", \\\' = \'

追问

转义符不太会用,能给个列子吗

回答

var zz =\"<tr style=\\\"height:25px\\\">\";

本文地址:https://www.stayed.cn/item/9799

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。