有没有办法在输入字段获得焦点时更改div的CSS边框(例如,当它失去焦点时,删除边框). HTML: input type="text" name="title" id="title"/inputdiv id="mainTitle"The Main Title/div CSS: #mainTitle { border: 1px solid
HTML:
<input type="text" name="title" id="title"></input> <div id="mainTitle">The Main Title</div>
CSS:
#mainTitle { border: 1px solid #ccc; }
$(function() { //aka document.ready $("input#title").focus( function() { $("div#mainTitle").css("border","1px solid #ccc"); }); $("input#title").blur( function() { $("div#mainTitle").css("border",""); }); });