开发者

Focus input box when a div is clicked

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜