kar*_*ary 5 javascript ajax onclick href
最近,我看到很多站点都有可点击的对象,这些对象在html代码中没有任何href或onclicks.我也尝试过警告他们的href,onclick,onmousedown,onmouseup属性,但它只是说"undefined".我注意到这些页面中有很多复杂的javascript.
一个网站特别让我困惑:http: //www.sharenator.com/Boy_Teaches_His_Puppy_How_to_Eat/#/doggy_01_Boy_Teaches_His_Puppy_How_to_Eat-0.html
它实际上非常好.按钮也不可选.按钮的ID为nextBtn,nextBtn2,prevBtn和prevBtn2.
任何人都知道如何实现这个?
您可以使用jQuery的.click(callback)函数(http://api.jquery.com/click/)或.delegate(selector,'click',callback)(在jQuery 1.7之前)和.on('click',选择器,回调)(jQuery 1.7+)或.bind('click',回调)。
感谢Anthony Grist指出.live()现在已被弃用:)
因此:
<button id="clickable">Click Me!!</button>
Run Code Online (Sandbox Code Playgroud)
然后使用jQuery定位按钮:
$("#clickable").click(function(){
// Send user to this link
location.href = "http://www.takemehere.com";
});
Run Code Online (Sandbox Code Playgroud)
您可以在我给的链接以及jQuery的主页上了解更多有关此的内容。
更新
实际页面通过以下方式处理此问题:
$('#prevBtn').mousedown (onBackward);
Run Code Online (Sandbox Code Playgroud)
哪个onmousedown调用:
function onBackward () {
showImg (currentId - 1);
}
Run Code Online (Sandbox Code Playgroud)
箭头键的使用:
$(document).keyup (function (event) {
var activeElement = document.activeElement.tagName;
if (activeElement == 'INPUT' || activeElement == 'TEXTAREA') return;
//alert (window.location.pathname);
if (event.keyCode == 39) onForward();
else
if (event.keyCode == 37) onBackward();
});
Run Code Online (Sandbox Code Playgroud)
有关幻灯片放映的源代码,请参见http://www.sharenator.com/js/slideshow.js。
| 归档时间: |
|
| 查看次数: |
5606 次 |
| 最近记录: |