繁体   English   中英

超级链接未在新标签页中打开

[英]hyperlink doesn't open in a new tab

我重新设计了我的网站,但超链接出现了问题,请参阅我的代码,我认为问题出在js中

<li class="product aopc">
        <a class="product-link"></a>
        <div class="product-details mCustomScrollbar">
    <a target="_blank" href="my link in pdf"><i class="material-icons">picture_as_pdf</i></a>
    </li>

和我的js的一部分

// handle click events
$container.on( 'click', '.product', function( event ) {
    var $this = $( this );

    event.preventDefault();

    // if not already open, do so
    if ( !$this.hasClass( 'open' ) ){
        var $openItem = $container.find( '.open' );

        // if any, close currently open items
        if ( $openItem.length ) {
            closeItem( $openItem );
        }

        openItem( $this );
    }
});

和这个:$ container.on('click','.close',function(event){event.stopPropagation(); closeItem($(this ..closest('.product'));});

function openItem( $item ) {
    var $image = $item.find( '.product-image' );

    $item.addClass( 'loading' ).spin( spinJsConfiguration );

    $image.attr( 'src', $image.data( 'src-large' ) );

    $item.imagesLoaded( function() {
        $item.spin( false ).removeClass( 'loading' ).addClass( 'open' );
        $container.addClass( 'item-open' ).isotope( 'reLayout' );
        $item.append( '<div class="close">&times;</div>' );
    });
}
function closeItem( $item ) {
    $item.removeClass( 'open' ).find( '.close' ).remove();
    $container.removeClass( 'item-open' ).isotope( 'reLayout' );
}
});

任何帮助,将不胜感激

由于点击处理程序,该链接无法正常工作。 您的链接是li .product的子级。

点击处理程序包含preventDefault()。 删除该链接将使链接再次工作。

编辑:根据您的评论,更改以下内容:

$container.on( 'click', '.product', function( event ) {
    var $this = $( this );

至:

$container.on( 'click', '.product-link', function( event ) {
    var $this = $( this ).parent();

并且不要删除preventDefault()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM