0

我有以下脚本,当您单击 div 中的图像时,它会在新窗口中打开相应的 href 链接。同时,在父页面被点击的 div 被隐藏,显示下一个 div。

还有一个“下一步”按钮,所以为了前进到下一个 div 而不点击图像。此“下一步”按钮不会打开当前 div 上的相应 a href。它只是跳到下一个 div。

这一切都很完美,但是我现在尝试添加一个按钮,单击该按钮将带您到可见 div 的 href 位置。

那有意义吗?

这是一个 JSFiddle 演示:http: //jsfiddle.net/QTyRq/

这是代码...

<div id="container">
    <div class="imgrotation"><a href="http://google.com" target="_blank"><img src="abc.jpg" width="100" height="100" border="0" /></a></div>
    <div class="imgrotation"><a href="http://yahoo.com" target="_blank"><img src="def.jpg" width="200" height="200" border="0" /></a></div>
    <div class="imgrotation"><a href="http://msn.com" target="_blank"><img src="ghi.jpg" width="300" height="300" border="0" /></a></div>
    <div class="imgrotation"><a href="http://bing.com" target="_blank"><img src="jkl.jpg" width="400" height="400" border="0" /></a></div>
</div>

<button id="nextimg">Next Image</button>

<!--This is what I need added to JS -->
<button id="gotourl">Visit Site</button>

查询:

var alldoneURL = 'next-image-group.html'; //final click
function next(event, duration) {
    duration = duration || 900; // default value
    var that = $('.imgrotation:visible');
    if (that.next('.imgrotation').length) {
        that.fadeOut(duration, function() {
            that.next('.imgrotation').fadeIn(duration);
        });
    } else {
        window.location.href = alldoneURL;
    }
    return false;
}

$('.imgrotation').not(':first').hide();
$('.imgrotation a').click(

function(e) {
    e.preventDefault();
    var newWin = window.open(this.href), //(this.href, 'newWindow') to load all clicks in one window.open
        duration = 900;
    next(e, duration);
});
$('#nextimg').click(next);

​</p>

4

1 回答 1

1

添加这个jquery也可以

$('#gotourl').on('click',function(){
      window.open($(".imgrotation:visible a").prop('href'));
});

​ ​</p>

http://jsfiddle.net/QTyRq/3/

function$('#gotourl').on('click',function(){
    window.open($(".imgrotation:visible a").prop('href'));
    $('#nextimg').trigger('click');
});

​<a href="http://jsfiddle.net/QTyRq/4/" rel="nofollow">同时更新了 JSFIDDLE

于 2012-05-22T19:32:31.663 回答