超链接无法在新选项卡中打开

时间:2016-04-06 18:49:47

标签: javascript hyperlink

我重新设计我的网站,我有一个超链接的问题看到我的代码我认为问题是在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' );
}
});

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:2)

The link doesn't work because of the click handler. Your link is a child of the li .product .

The click handler contains preventDefault(). Removing that would make the link working again.

Edit: Based on your comment, change the following:

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

To:

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

And don't remove preventDefault().