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.
精彩评论