无法识别的表达式:[object Object] .class:jquery

时间:2018-10-11 13:45:43

标签: javascript jquery

我的网站上有一个菜单,它只在我单击肉体时发生 但是我想要如果我单击菜单标题下拉菜单 我上课没事 然后,我尝试使用jquery进行工作,但是在第一次单击中所有菜单滚动条中出现,但是第二次显示i错误

这是我的html:

var requests = (from req in db.PartRequests
                join info in db.UsersInfos on req.UserId equals info.aspnet_UserId
                join prodName in db.Products on req.ProductId equals prodName.Id
                join partRequestStatus in db.PartRequestStatus on req.PartRequestStatusId equals partRequestStatus.Id           
                select new ShowRequestsModel
                {                                                                                                                
                    WarantyExpirationDate = req.PurchasedDate.AddYears(2),
                    IsWarantyExpired = false
                })
                .Sort(sortField, sortBy);

这是我的js:

<ul id="responsive-menu" class="">
    <li id="responsive-menu-item-20419" class=" responsive-menu-item-current-ancestor">
        <a href="http://HappyHelps.com/conseils-bac-de-francais/" class="responsive-menu-item-link">Commence ici !</a>
    </li>
    <li id="responsive-menu-item-6434" class="responsive-menu-item-current-ancestor">
        <a class="responsive-menu-item-link">Méthode
        <div class="responsive-menu-subarrow">▼</div>
        </a>
    </li>
    <ul class="responsive-menu-submenu responsive-menu-submenu-depth-1">
        <li id="responsive-menu-item-19480" class=" responsive-menu-item-current-ancestor">
            <a href="http://HappyHelps.com/bac-de-francais-ecrit/" class="responsive-menu-item-link">Écrit
            <div class="responsive-menu-subarrow">▼</div>
            </a>
        </li>
        </ul>
</ul>

这就是我得到的错误:

  

未捕获的错误:语法错误,无法识别的表达式:[objectObject] .response-menu-subarrow

3 个答案:

答案 0 :(得分:1)

我想您应该使用如下的jQuery代码:

jQuery('.responsive-menu-item-link').click(function(){
    var clicked = jQuery(this);
    jQuery( clicked ).find(".responsive-menu-subarrow").trigger( "click" );
});

答案 1 :(得分:1)

在您的代码中,clicked不是对象,因此.trigger()函数会出错。

尝试一下:

jQuery('.responsive-menu-item-link').click(function(){
     var clicked = jQuery(this);
    jQuery(clicked).find(".responsive-menu-subarrow").trigger( "click" );
 });

答案 2 :(得分:0)

var clicked = jQuery(this);将返回.responsive-menu-item-link的DOM元素对象

尝试jQuery(".responsive-menu-item-link .responsive-menu-subarrow").trigger( "click" );