简体   繁体   中英

Toggle text input when RadioBox input checked

I'm trying to connect between radiobox when it is clicked, to toggle (I mean automaticly click on) the text input

So, I did the following:

<input type="radio" name="t" value=""  onclick="<!-- Connect to text input !-->"> Radio 1
<input type="text" id="x" name="xx" placeholder="Test">

How should I go about this ?

如果要将焦点设置到文本框,可以使用:

<input type="radio" name="t" value=""  onclick="document.getElementById('x').focus();"> Radio 1

This would do, you have to use document.querySelector('#x').focus() , where x is the "id" of text input.

<input type="radio" name="t" value=""  onclick="document.querySelector('#x').focus()"> Radio 1
<input type="text" id="x" name="xx" placeholder="Test">

try this with jquery:

<input type="radio">
<input type="text">
** <script>
  $('input[type="radio"]:checked + input[type="text"]').focus();
</script>**

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