使用jQuery访问下一页
我想通过单击键盘上的下一步按钮(右箭头>)进入下一步。 我该怎么做? 我找到了一个解决方案,但在100%成功之前失败了使用jQuery访问下一页,jquery,Jquery,我想通过单击键盘上的下一步按钮(右箭头>)进入下一步。 我该怎么做? 我找到了一个解决方案,但在100%成功之前失败了 <html> <head> <script src="jquery-1.4.2.js"></script> <script src="jquery.hotkeys.js"></script> <script> //
<html>
<head>
<script src="jquery-1.4.2.js"></script>
<script src="jquery.hotkeys.js"></script>
<script>
//This page is a result of an autogenerated content made by running test.html with firefox.
function domo() {
jQuery(document).bind('keydown', 'right', function (evt) {
location.href = $('#previous_page_link').href;
//window.location.href = 'http://www.google.com';
});
}
jQuery(document).ready(domo);
</script>
</head>
<body>
<a id="previous_page_link" href="http://www.google.com">Google</a>
<a id="next_page_link" href="http://www.yahoo.com">Yahoo</a>
</body>
</html>
//此页面是通过使用firefox运行test.html自动生成内容的结果。
函数domo(){
jQuery(document).bind('keydown','right',function(evt){
location.href=$(“#上一页_链接”).href;
//window.location.href=http://www.google.com';
});
}
jQuery(document).ready(domo);
试试:
jQuery(document).ready(function() {
jQuery(document).bind('keydown', 'right', function () {
location.href = $('#previous_page_link').attr('href');
});
});
为什么需要在
文档中绑定。就绪
?您正在将事件绑定到文档本身。他正在使用热键插件,该插件为他执行右箭头键检查。@Interstarr_编码器在附加事件之前等待DOM准备就绪。谢谢,它工作正常。我用不同的浏览器测试了它。在Windows7上开发ie789、ff、chrome和opera。谢谢。@VisioN tbh,我会自己检查,而不是依赖插件来完成简单的工作。@mgraph,你的解决方案正在运行。谢谢