<!DOCTYPE html><html lang="en"><head> ? ?<meta charset="UTF-8"> ? ?<title>函數(shù)接收參數(shù)并彈出</title></head>?<style> ? ?body{font:12px/1.5 Tahoma;text-align:center;} ? ?code,input,button{font-family:inherit;} ? ?input{border:1px solid #ccc;padding:3px;} ? ?button{cursor:pointer;} ? ?</style> ? ?<script> ? ?var myFn = function(a, b) ? ?{ ? ? alert(a.value); ? ? alert(b.value)
? ?}; ? ?window.onload = function () ? ?{ ? ? var oInput = document.getElementsByTagName("input"); ? ? var oBtn = document.getElementsByTagName("button")[0]; ? ? oBtn.onclick = function() ? ? { ? ? myFn(oInput[0],oInput[1]) ? ? } ? ?}; ? ?</script> ? ?</head> ? ?<body> ? ?<p><input type="text" value="北京市" /></p> ? ?<p><input type="text" value="朝陽區(qū)" /></p> ? ?<p><button>傳參</button></p> ? ?</body> ? ?</html> ? ?如上所述,不懂為什么button標(biāo)簽需要下標(biāo)[0],我試了去掉下標(biāo),點(diǎn)擊按鈕沒有反應(yīng)一開始我理解的是input標(biāo)簽才需要下標(biāo)還請(qǐng)各位前輩幫忙解答,感激不盡
為什么button標(biāo)簽只有一個(gè)還要下標(biāo)
刺槐少女
2018-03-18 18:20:08