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

动态改变onclick的值, 想写个JS涵数,先给onClick赋值,再去点击被赋值的HTML控件.为什么不行,请高人看.
动态改变onclick的值,   想写个JS涵数,先给onClick赋值,再去点击被赋值的HTML控件.为什么不行,请高人看.

<SCRIPT   type= "text/javascript "   language= "javascript ">

                function   init(){
var   vWidth   =   "100 ";
var   vHeight   =   "100 ";
var   vImgPath   =   "1.jpg ";
var   vonClick   =   "playVideo() ";
var   vonMouseOver   =   "playVideo() ";
var   vonMouseOut   =   "playVideo() ";

document.getElementById( "playButton1 ").width   =   vWidth   ;       //可以显示
document.getElementById( "playButton1 ").height=   vHeight   ;//可以显示
document.getElementById( "playButton1 ").src   =   vImgPath   ;//可以显示
document.getElementById( "playButton1 ").onClick   =   vonClick   ;   //不可以.
document.getElementById( "playButton1 ").onMouseOver   =   vonMouseOver   ;//不可以.
document.getElementById( "playButton1 ").onMouseOut   =   vonMouseOut   ;//不可以.
                }

                function   playVideo()   {
                        :
              }
</SCRIPT>


 

<BODY   onload=init()>  
<IMG   src= " "   name= "playButton1 "   width= " "   height= " "   border= "0 "   id= "playButton1 "   onClick= " "   onMouseOver= " "   onMouseOut= " "   class= "link "/>
                :  
                :



------解决方案--------------------

<SCRIPT type= "text/javascript " language= "javascript ">

function init(){
var vWidth = "100 ";
var vHeight = "100 ";
var vImgPath = "1.jpg ";
var vonClick = "playVideo ";
var vonMouseOver = "playVideo ";
var vonMouseOut = "playVideo ";

document.getElementById( "playButton1 ").width = vWidth ; //可以显示
document.getElementById( "playButton1 ").height= vHeight ;//可以显示
document.getElementById( "playButton1 ").src = vImgPath ;//可以显示
document.getElementById( "playButton1 ").onClick = vonClick ; //不可以.
document.getElementById( "playButton1 ").onMouseOver = vonMouseOver ;//不可以.
document.getElementById( "playButton1 ").onMouseOut = vonMouseOut ;//不可以.
}

function playVideo() {
:
}
</SCRIPT>




<BODY onload=init()>
<IMG src= " " name= "playButton1 " width= " " height= " " border= "0 " id= "playButton1 " onClick= " " onMouseOver= " " onMouseOut= " " class= "link "/>
:
:

------解决方案--------------------
var vWidth