开发者

simple onmouseover to call javascript not working

开发者 https://www.devze.com 2022-12-23 07:42 出处:网络
In a simple html page I have: 开发者_Python百科<SCRIPT> function Clicker(number){ if (number == 1)

In a simple html page I have:

开发者_Python百科<SCRIPT>
function Clicker(number){
if (number == 1) 
document.write ('<style type="text/css">body {background-color: #cccccc;}</style>');
}
</SCRIPT>

and in the html body:

<a onmouseclick="Clicker(1)" href="#">clic</a>

But when I click on the link nothing happens. Where am I wrong?


Writing the style block probably won't effect a change in the background colour. To do that you have to manipulate the Document object:

<script type="text/javascript">
function Clicker(number){
if (number == 1) 
    document.body.style.background='#cccccc';
}
</script>

Your click event should also be onclick:

<a onclick="Clicker(1)" href="#">clic</a>


Simply change onmouseclick to onclick.


You need 'onclick' like following.

<a onclick="Clicker(1)" href="#">clic</a>
0

精彩评论

暂无评论...
验证码 换一张
取 消