課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
是不是可以直接通過id得到一個(gè)對(duì)象,就是直接用它的id當(dāng)做一個(gè)對(duì)象 而不需要通過getElementById()?
2015-02-11
源自:JavaScript入門篇 3-6
正在回答
是的,您可以直接把id方進(jìn)function里
舉例<script>
function multiply(val1,val2,val3,ans){
????ans.value = val1*val2*val3;
}
</script>
<input type=text id='qty' >
<input type=text id='unit' >
<input type=text id='unitp' >
<input type=text id='ans' onclick='multiply(qty,unit,unitp,ans);' >
把數(shù)值填進(jìn)qty,unit,unitp然后點(diǎn)擊最后的格子就會(huì)跑multiply的funtion
derrick9006
_so_now 提問者 回復(fù) derrick9006
舉報(bào)
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
1 回答JS可以直接用id名操作對(duì)象嘛?
2 回答為什么要通過ID獲取元素 不可以直接用document.write嗎
1 回答通過ID獲得元素
2 回答為什么慕課網(wǎng)一直說這個(gè)代碼通不過,不能直接通過。。。
2 回答直接用id名作為對(duì)象設(shè)置寬高怎么不行?其他都可以
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-02-11
是的,您可以直接把id方進(jìn)function里
舉例
<script>
function multiply(val1,val2,val3,ans){
????ans.value = val1*val2*val3;
}
</script>
<input type=text id='qty' >
<input type=text id='unit' >
<input type=text id='unitp' >
<input type=text id='ans' onclick='multiply(qty,unit,unitp,ans);' >
把數(shù)值填進(jìn)qty,unit,unitp然后點(diǎn)擊最后的格子就會(huì)跑multiply的funtion