简体   繁体   中英

Set input text default value and select option value then disable

Using JavaScript, how can I:

  • set a default value (and disable it) on the textbox
  • disable the <select> option "Days"

? This is my HTML:

Deliver every <input type="text" maxlength="2" size="3"> 
<select>
<option value="Days">Days</option>
<option value="Weeks">Weeks</option>
</select>

I hope this one would work.

<input type="text" id="defaultDays" size="3">
<select id="disableOption">
<option value="Days">Days</option>
<option value="Weeks">Weeks</option>
</select>

<script type="text/javascript"> 
  document.getElementById('defaultDays').setAttribute('value','28');
  document.getElementById('defaultDays').disabled = true;
  document.getElementById('disableOption').disabled = true;
</script>

Thank you guys for your previous comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM