str = '<a herf="http://.../..." >text</a>';
//上面这句, 我要在下面那些输出, 怎么处理的?<input text="type" value="我要把str插进来这里,但双引号没办法转义" />
// 因为str是动态获得的, 怎么给它加上 \ 转义

解决方案 »

  1.   

    属性中的双引号用 &quot;
    <input text="type" value="&quot;" />用js赋值的话应该不需要转换的。<script type="text/javascript">
    var str = '<a herf="http://.../..." >text</a>';
    window.onload=function(){
       document.getElementById("txt").value = str;
    }
    </script>
    <input id="txt" value="" />
      

  2.   


    我把str插入把其它str1 去了, 再赋值就有问题了
      

  3.   

    问题我解决了, 想问一下, 如果要用replace转换怎么弄str.replace('/"/g','&quot;'); //这样没效果