Click on
to focus <input>

前端 未结 6 1295
时光说笑
时光说笑 2020-12-30 22:54

I have a series of input elements each with a few

tags separate.
I like to have if where I can click on any of the
相关标签:
6条回答
  • 2020-12-30 23:32
    $('div').click(function() {
        $(this).find('input[type="text"]').focus();
    });​
    

    LIVE DEMO

    0 讨论(0)
  • 2020-12-30 23:35

    I don't see a reason why you need JS to do this when such feature is already provided in HTML.

    <label for="YOURID">The clickable region<label>
    <input id="YOURID" type="text" />
    
    0 讨论(0)
  • 2020-12-30 23:37

    Try this :

    <input id="myInput" />
    <div onclick="document.getElementById('myInput').focus(); return false;"></div>
    
    0 讨论(0)
  • 2020-12-30 23:41
    1. USING HTML ("for") :

      HTML provides this functionality. Using "for" "id" you can easily achieve it.

     <label for="idname">Click Here to Reach Input<label>
     <input id="idname" type="text">
    
    1. USING jQuery ("focus")

    $(".classname").click(function(){

    $("input").focus(); })

    0 讨论(0)
  • 2020-12-30 23:42
    1. using javascript (call .focus() on the input element)
    2. using wrapped around your div (makes only sense if the div is the label)
    0 讨论(0)
  • 2020-12-30 23:43

    Try this with jquery:

    $('#yourdiv').click(function() {
         $('#yourfield').focus();
    });
    
    0 讨论(0)
提交回复
热议问题