html中单双引号镶嵌

html中单双引号镶嵌

例如下面右键菜单的例子

由于点击了菜单中个子菜单 需要促发某个函数 函数存在参数 所以出现了三次单双引号问题

<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script>
  function mousePosition(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
  function createMenu(menuName,childArray,controlArray){
  if(document.getElementById(menuName)!=null){
      document.body.removeChild(document.getElementById(menuName));
   }
   var dv= document.createElement("div");
   dv.id=menuName;
 dv.style.zIndex="2000";
 var c=event.srcElement;
 var rwidth=200;
    var htmlDiv="<table style=\"border:1px solid black;border-collapse:collapse;background-color:white\" width=\""+rwidth+"px\" >";
      for(var i=0;i<childArray.length;i++){
       if(i%2==1){
        htmlDiv+="<tr onclick='"+controlArray[i]+";document.body.removeChild(document.getElementById(\""+menuName+"\"))' style=\"FONT-FAMILY: Arial, 宋体; FONT-SIZE: 12px;height:20px;width:"+rwidth+"\""+
        "onmouseover=\" for(var i=0;i<this.parentNode.parentNode.rows.length ;i++){ if(i%2==1){ this.parentNode.parentNode.rows[i].style.background='#eeeeee'; } else{ this.parentNode.parentNode.rows[i].style.background=''; } this.parentNode.parentNode.rows[i].style.color='black'; } ;this.style.background='#0a246a';this.style.color='white';this.parentNode.parentNode.setAttribute('currentCount',"+i+")\""+
        "onmouseout=\"this.style.background='';this.style.color='black'\"><td>"+childArray[i]+
        "</td></tr>";
       }else{
        htmlDiv+="<tr onclick='"+controlArray[i]+";document.body.removeChild(document.getElementById(\""+menuName+"\"))' onmouseover=\" for(var i=0;i<this.parentNode.parentNode.rows.length ;i++){ if(i%2==1){ this.parentNode.parentNode.rows[i].style.background='#eeeeee'; } else{ this.parentNode.parentNode.rows[i].style.background=''; } this.parentNode.parentNode.rows[i].style.color='black'; } ;this.style.background='#0a246a';this.style.color='white';this.parentNode.parentNode.setAttribute('currentCount',"+i+")\"onmouseout=\"this.style.background='#eeeeee';this.style.color='black'\" style=\"FONT-FAMILY: Arial, 宋体;FONT-SIZE: 12px;background-color:#eeeeee;height:20px;width:"+rwidth+"\"><td >"+childArray[i]+"</td></tr>";
       }
      }
 htmlDiv+="</table>";
 var motions=mousePosition(event);
 var yonclick=document.onclick;
 document.onclick=function(){
 if(document.getElementById(menuName)!=null){
     eval(yonclick);
  document.body.removeChild(document.getElementById(menuName));
 }
 } 
 dv.innerHTML=htmlDiv;
 dv.style.top=motions.y;
 dv.style.left=motions.x;
 dv.style.width=rwidth;
 dv.style.position="absolute";
 document.body.appendChild(dv);

  }
  function aaa(ggg){
     alert(ggg);
  }
  function bbb(){
    //alert('bbb');
 
  }
 
  </script>
 </head>
 
 <body onclick="alert('abc')">
  <table>
      <tr oncontextmenu="javascript:createMenu('mymenu',['aaa','bbb'],['aaa(document.getElementById(&quot;abcc&quot;).value)','bbb()']);return false;">
   <td>111111111111</td>
   </tr>
      <tr oncontextmenu="javascript:createMenu('mymenu',['aaa','bbb'],['aaa(document.getElementById(&quot;abcc&quot;).value)','bbb()']);return false;">
   <td>222222222222</td>
   </tr>
  </table>
  <input type="text" id="abcc" value="111"/>
 </body>
</html>

------------------------------------------------------》
双引号 下面有单引号 下面又有字符串 怎么处理
在单引号下一层使用双引号转移字符&quot; 会等语法分析通过后 自动被替换双引号
直接如果写成双引号 会无法通过语法验证
一般处理思路为 先双引号 在单引号  在&quot;

posted @ 2012-12-04 18:34  饺子吃遍天  阅读(129)  评论(0编辑  收藏  举报