没有HREF按钮的onclick等 [英] buttons with no href, onclick etc

查看:151
本文介绍了没有HREF按钮的onclick等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我已经看到了很多有没有在他们的HTML code任何的HREF或onclicks可点击对象的网站。我也试图提醒他们HREF,的onclick,onmousedown事件,onmouseup属性,但它只是说不确定。我也注意到,有很多在这些网页复杂的JavaScript。

Lately, I've been seeing a lot of sites that have clickable objects that don't have any hrefs or onclicks in their html code. I also tried alerting their href, onclick, onmousedown, onmouseup attributes but it only says "undefined". I do notice that there's a lot of complicated javascript in these pages.

在特定的一个网站,我大惑不解: <一href="http://www.sharenator.com/Boy_Teaches_His_Puppy_How_to_Eat/#/doggy_01_Boy_Teaches_His_Puppy_How_to_Eat-0.html" rel="nofollow">http://www.sharenator.com/Boy_Teaches_His_Puppy_How_to_Eat/#/doggy_01_Boy_Teaches_His_Puppy_How_to_Eat-0.html

one site in particular baffles me: http://www.sharenator.com/Boy_Teaches_His_Puppy_How_to_Eat/#/doggy_01_Boy_Teaches_His_Puppy_How_to_Eat-0.html

它实际上是pretty的好。这些按钮是不可选的为好。按钮的ID是nextBtn,nextBtn2,prevBtn和prevBtn2。

It's actually pretty good. The buttons aren't selectable as well. The ids of the buttons are nextBtn, nextBtn2, prevBtn and prevBtn2.

任何人有任何想法如何实现这一点?

Anybody has any idea how to implement this?

推荐答案

您可以使用jQuery的。点击(回调)函数(的 http://api.jquery.com/click/ )或.delegate(选择,点击,回调)(之前的jQuery 1.7)和。对('点击',选择,回调)( jQuery的1.7+)或.bind('点击',回调)。

You can use jQuery's .click(callback) function (http://api.jquery.com/click/) or .delegate(selector, 'click', callback) (prior to jQuery 1.7) and .on('click', selector, callback) (jQuery 1.7+) or .bind('click', callback).

感谢安东尼·格里斯特为指出.live()现在去precated:)

Thanks to Anthony Grist for pointing out that .live() is now deprecated :)

像这样:

<button id="clickable">Click Me!!</button>

然后瞄准按钮使用jQuery:

Then target the button with jQuery:

$("#clickable").click(function(){
    // Send user to this link
    location.href = "http://www.takemehere.com";
});

您可以阅读更多关于这个我给的链接,并在jQuery的网页。

You can read more about this on the link I gave, and on jQuery's homepage.

更新

实际的页面处理这有:

$('#prevBtn').mousedown (onBackward);

这将onmousedown事件的呼叫:

Which would onmousedown call:

function onBackward () {
    showImg (currentId - 1);
}

使用箭头键:

The use of arrow keys:

 $(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();
});

请参阅 http://www.sharenator.com/js/slideshow.js 为幻灯片显示的源$ C ​​$ C。

See http://www.sharenator.com/js/slideshow.js for the source code of the slideshow.

这篇关于没有HREF按钮的onclick等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆