關(guān)于click事件添加方法
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="texthtml; charset=utf-8">
<title>計時器</title>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" id="stop" />
? </form>
</body>
<script type="text/javascript">
? ?function clock(){
? ? ? var time=new Date(); ? ? ? ? ? ? ? ?
? ? ? document.getElementById("clock").value = time;
? ?}
var a = setInterval("clock()",100)
document.getElementById("stop").onclick=clearInterval(a);
</script>
<html>
如果在input元素內(nèi)加上onclick="clearInterval(a)"是可以實現(xiàn)的。在script標(biāo)簽內(nèi)只能寫一個function,再onclick=function名,也可以實現(xiàn)。但是在script標(biāo)簽內(nèi)怎么實現(xiàn)不寫function,即onclick=function內(nèi)容,能實現(xiàn)得了嗎?
2016-07-24
把你的那句改成document.getElementById("stop").onclick=function(){
??????? clearInterval(a)
??? };就可以運行了,具體原因我也不清楚
2016-07-23
可以吧。像<input type="button" value="add"? onclick="{document.write( 2+3)}"/>這句代碼就可以輸出結(jié)果5,而document.write( 2+3)可以作為一個函數(shù)的具體內(nèi)容
2016-07-21
新手在學(xué),聽大神說可以,具體寫法我也不會。
2016-07-21
能實現(xiàn)