日期:2014-05-16  浏览次数:20378 次

(这个问题你们肯定遇见)求助:这句话该怎么写:vartempHtml ="<INPUT type='button' name='but' onclick='nihao(" + movName + ")' value='
求助:这句话该怎么写:vartempHtml   = " <INPUT   type= 'button '   name= 'but '   onclick= 'nihao( "   +   movName   +   ") '   value= ' "   +   movName   +   " '> ";

一事件触发   javaScript中的   test()涵数,涵数里面写一个 'button '   A   ,   'button '   A   的事件是调用nihao()     这样写后,编译出错,说我XXXa没定义,谁能帮帮我,改善下vartempHtml   = " <INPUT   type= 'button '   name= 'but '   onclick= 'nihao( "   +   movName   +   ") '   value= ' "   +   movName   +   " '> ";
话,
    我调试了一下午都没搞定,请求帮助.这个问题你们肯定遇见
原代码如下:

function   test(urlName)   {

var   movName   =   "XXXa ";
 
      alert(urlName);

          var   vartempHtml   = " <INPUT   type= 'button '   name= 'A '   onclick= 'nihao( "   +   movName   +   ") '   value= ' "   +   movName   +   " '> ";

alert(vartempHtml);

document.getElementById( "LayerTitle ").innerHTML   =   vartempHtml;

}

function   nihao(a){

alert(a);

}


------解决方案--------------------
<html>
<script>
function test(urlName) {

var movName = "XXXa ";

alert(urlName);

var vartempHtml = " <INPUT type= 'button ' name= 'A ' onclick= 'nihao(\ " " + movName + "\ ") ' value= ' " + movName + " '> ";

alert(vartempHtml);

document.getElementById( "LayerTitle ").innerHTML = vartempHtml;

}

function nihao(a){

alert(a);

}
</script>
<body onLoad= "test( 'dd ') ">
<div id= "LayerTitle "> </div>
</body>
</html>