简体   繁体   中英

Inline JavaScript enable/disable select and text box on click radio button

I am trying inline script to enable disable with radio button, but it is not working. How to do that?

<form>
<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
<br><br>
<input type="radio" name="ph" onclick=" document.getElementById("mySelect").disabled=true;" value="Disable list">DISABLE
<input type="radio" name="ph" onclick="enable()" value="Enable list">ENABLE
</form>

You can even see it at the syntax highlighter. Your JavaScript in the onclick event contains " , but they're special characters for HTML. You have to escape them with backslashes like

<tag onclick="alert(\\"hello\\");">

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