问一个很easy的单双引号嵌套问题
第7行如果非要给超链接的onclick方法赋值的话, 怎么传参数不会出js错误?就是单双引号嵌套老不对.
<html>
<head>
<script language= "javascript ">
function onPageLoad() {
var id = "www.csdn.net ";
var target = document.getElementById( "target ");
target.innerHTML= " <a href= '# ' onclick= 'openurl( " + id + "); '> openURL </a> ";
}
function openurl(id) {
// do something...
window.open( "http:// " + id);
}
</script>
</head>
<body onLoad= "onPageLoad(); ">
<div id= "target "> </div>
</body>
</html>
------解决方案-------------------- target.innerHTML= " <a href= '# ' onclick=\ "openurl( ' " + id + " ');\ "> openURL </a> ";
必要的时候,用一下转义符