我對java和javascript有點新鮮。我想知道如何循環下面的腳本,以便我不需要創建如此多的代碼行。該腳本用於禁用字段並僅在用戶選中該複選框時啓用它們。在javascript中循環禁用字段
<script>
function start() {
form1.s_Name.disabled = true;
form1.r_Name.disabled = true;
form1.s_Address.disabled = true;
form1.r_Address.disabled = true;
form1.s_Postal.disabled = true;
form1.r_Postal.disabled = true;
form1.s_City.disabled = true;
form1.r_City.disabled = true;
form1.s_Email.disabled = true;
form1.r_Email.disabled = true;
form1.s_Phone.disabled = true;
form1.r_Phone.disabled = true;
}
onload = start;
function chgtx() {
form1.s_Name.disabled = !form1.chkChange.checked;
form1.r_Name.disabled =!form1.chkChange.checked;
form1.s_Address.disabled = !form1.chkChange.checked;
form1.r_Address.disabled = !form1.chkChange.checked;
form1.s_Postal.disabled = !form1.chkChange.checked;
form1.r_Postal.disabled = !form1.chkChange.checked;
form1.s_City.disabled = !form1.chkChange.checked;
form1.r_City.disabled = !form1.chkChange.checked;
form1.s_Email.disabled = !form1.chkChange.checked;
form1.r_Email.disabled = !form1.chkChange.checked;
form1.s_Phone.disabled = !form1.chkChange.checked;
form1.r_Phone.disabled = !form1.chkChange.checked;
}
我覺得形成的代碼,你可以看到,只有form1.s_
和form1.r_
和!form1.chkChange.checked;
是固定的,重複的。
你能告訴我如何將這段代碼轉換成循環風格,以提高效率嗎?
的JavaScript不是Java – gefei