Tom*_*Tom 12 javascript jquery dom javascript-events
我试图这样做,当用户在文本框中并按Enter键时,它与单击链接相同,在这种情况下它应该将它们带到另一个页面.这就是我所拥有的,它不起作用.
//jQuery
$(document).ready(function() {
//if focus is in the input box drivingSchoolInput
$("#drivingSchoolInput").live("click", function() {
//if enter key is pressed
if(e.keyCode == 13) {
//click the button and go to next page
$("#button1").click();
}
});
});
Run Code Online (Sandbox Code Playgroud)
<form>
<div class="formDiv">
<label for="City">Search by Driving School</label>
<span class="inputBox"><input type="text" name="City" class="input" id="drivingSchoolInput" /></span>
</div>
<h4 class="submitButton"><a href="school.html" id="button1">Submit</a></h4>
</form>
Run Code Online (Sandbox Code Playgroud)
Jac*_*kin 14
写一个小的jQuery插件:
jQuery.fn.enter = function(callback) {
if(!callback) {
//don't attach if we have garbage.
return;
}
$(this).keydown(function(e) {
var ev = e || event;
if(ev.keyCode == 13) {
callback();
return false;
}
});
};
Run Code Online (Sandbox Code Playgroud)
用法: $(element).enter(callback_func);
我希望这有帮助.
该行需要e:
$("#drivingSchoolInput").live("click", function(e) {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22056 次 |
| 最近记录: |