没有HREF按钮的onclick等按钮、HREF、onclick

2023-09-10 19:16:15 作者:倾心相遇,安暖相陪

最近,我已经看到了很多有没有在他们的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.

在特定的一个网站,我大惑不解: 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.