让哥崩溃的转义符

js中的字符串拼接经常用到转义符,特此记下:

var tserverItem = document.getElementById("serverItem");//这个是table下的<tbody>

 var tr1 = document.createElement('tr');//这是个table标签下的tr
  tr1.style.height = '25px';

  var td7 = document.createElement('td');//这是个table标签下的td
  td7.width = "155px";
  td7.style.textAlign = "center";

  var say = "服务启动成功";

  td7.innerHTML = "<img width=\"32px\" height=\"32px\" onclick=\"alert('" + say + "');\" onmouseover=\"zoomInImg(this)\" onmouseout=\"zoomOutImg(this)\" title=\"点击启动服务\" style=\"cursor: pointer; border: medium none;\" src=\"images/bt_start_o.png\">&nbsp;&nbsp;";

tserverItem.appendChild(tr1);

实现在<table><tbody></tbody></table>中添加tr和td

先在html中写好源代码如:

<img width="32px" height="32px" onclick="alert('服务启动成功!');" onmouseover="zoomInImg(this)" onmouseout="zoomOutImg(this)" title="点击启动服务" style="cursor: pointer; border: medium none;" src="images/bt_start_o.png">&nbsp;&nbsp;

然后把" 替换为 \"

再次感谢老赵....

posted @ 2011-06-25 19:07  Mygirl  阅读(220)  评论(1编辑  收藏  举报