开发者

Focus input box when a div is clicked

开发者 https://www.devze.com 2023-04-06 16:11 出处:网络
I have an input 开发者_Python百科inside a div element (id = \"edit). I was wondering how, onclick of the div area, I could activate the cursor in the input field.You could use a <label for=\"edit\"

I have an input 开发者_Python百科inside a div element (id = "edit). I was wondering how, onclick of the div area, I could activate the cursor in the input field.


You could use a <label for="edit"> element. That would focus the <input> element when clicked.


$("#myDiv").click( function() {
   $("#myTextField").focus();
});


$('#edit').click(function() {
     $(this).find('input').focus()
})


use .focus() function like this:

$('#yourDiv').click(function() {
    $('#yourInput').focus();
});


use .attr() to add and removeAttr() to remove attribute "disabled" for the text box on the event click on the div.

0

精彩评论

暂无评论...
验证码 换一张
取 消