How to simulate click event on an input box

后端 未结 2 1212
离开以前
离开以前 2021-01-25 02:05

I am trying to simulate click on an input box. When its clicked manually, a drop down auto suggestion box appears as suggestions about past searches. However, when I try to simu

相关标签:
2条回答
  • 2021-01-25 02:40

    If you want to use pure/native javascript, you can use the onfocus attribute of the input element to call a Js function.

    <script>
        function showButton(){
        document.getElementById('mybutt').style.display = "block";
    }
    </script>
    
    <body>
        <input id="myinp" type="text" placeholder="place" onfocus="javascript:showButton()"/> 
        <button id="mybutt" style="display:none;">OK</button>
    </body>

    In the above file, you should see the "OK" button appear when you click on the input field.

    0 讨论(0)
  • 2021-01-25 02:48

    You need to .focus() instead of .click()

    document.getElementbyClassName("gb_cf")[0].focus(); //or
    document.getElementbyId("gs_taif50").focus();
    
    0 讨论(0)
提交回复
热议问题