當頁面使用onload時,我必須設置價格。使用onload設置輸入焦點
<body style="border: solid 1px black; margin-left: auto;margin-right: auto;width: 500px;">
<form>
<fieldset style="margin:25px";><legend>Discount Calculator</legend>
<div style="text-align: right; margin-right: 25%;">
<label>Enter Price: <input onload = "thing()" type="text" name="price" id="price"></label><br><br>
</div>
</fieldset>
</form>
<script type="text/javascript">
function thing()
{
document.focus()
}
</script>
</body>
我知道我做錯了什麼。我可以通過使用document.findElementById("price").focus()
輕鬆地將其設置爲重點,但對於此作業,我需要將其作爲onload來完成。任何幫助,將不勝感激。
試'的window.onload =函數(){}' – miglio