Javascript onclick html和jquery不起作用

Javascript onclick html和jquery不起作用,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我的jQuery和html代码有问题,当我在包含onclick事件的元素中单击时,什么也没有发生 这是html代码 <a href='http://gomusic.designerbh.com/profile/bar_53d6af107ee03/'>Cabana</a> <a href='javascript:void(0)' onclick='actus("actuevent_53d6e48c65b68")' style='float:right;width:24

我的jQuery和html代码有问题,当我在包含onclick事件的元素中单击时,什么也没有发生

这是html代码

<a href='http://gomusic.designerbh.com/profile/bar_53d6af107ee03/'>Cabana</a>
<a href='javascript:void(0)' onclick='actus("actuevent_53d6e48c65b68")' style='float:right;width:24px;height:12px;background:url(http://gomusic.designerbh.com/img/arrow.png) no-repeat bottom center'></a>
<span style='float:right;color:#ccc;margin:0px 10px 0px 0px'>49 Minutes ago</span>
<div class='actusevent_53d6e48c65b68' style='z-index:1;position:absolute;width:200px;padding:10px;background:#fff;margin:10px 0px 0px 260px;border:1px solid #ccc;border-radius:5px'>content here</div>
但当我这样做时,代码会提醒值122,并且工作正常

function actus(b){
    alert('122');
}

我已经调试过了。我使用的是最新版本的Chrome和jquery-1.9.1.min.js

如果您选择了错误的javascript,请尝试

function actus(b){
            $(".actus"+b).hide();
        }

  onclick='actus("event_53d6e48c65b68")'

您的参数值与类的名称不同

请注意单击“ActusActEvent”和class='actusevent_53d6e48c65b68'

另一件事:您试图在actus中获取的元素肯定与您的参数值不匹配。我建议您将参数值更改为以event_uu而不是actuevent_uu开头,或者您可以将actus中元素的前缀更改为:$.actusevent_uu。

EDIT 要在下面添加Barmars注释,您可以简单地将其拆分:

function actus(b){
    var i = b.split('_');
    $(".actusevent_"+b[1]).hide();
}
看看你的类名,它包括一个下划线-\。你想要的是:

function actus(b){
    $(".actusevent_"+b).hide();
}
错误:

您试图调用$'.actus'+b.hide,而您的类实际上被称为actusevent。 您还缺少jQuery函数中的u。所以它永远不会起作用。 有更有效的方法可以做到这一点。如果您可以控制如何创建DOM元素,则可以创建如下内容:

<a href='javascript:void(0)' id="my-link" data-actus-event='53d6e48c65b68' style='float:right;width:24px;height:12px;background:url(http://gomusic.designerbh.com/img/arrow.png) no-repeat bottom center'></a>

是否有id为actusactuevent_53d6e48c65b68的元素?我在HTML中没有看到。这是一个类,我已经更改了上面的代码。对不起!但是till不起作用,你也没有把它作为类名。该函数在参数的开头添加了actus。如果您发现有输入错误,您没有将类名和函数中的名称拼写相同?您想要->onclick='actusevent_53d6e48c65b68'friend我已经更改了它,但仍然不起作用它不会返回我anything@MarcosBrinner您的类名以actusevent开头,函数的参数以actuevent no.s.$.actus+b.hide开头;我正在使用,但什么都没有HTML中没有class=actusactevent_53d6e48c65b68。@Barmar它对我有效,发生的是我正在传递actus['idhere']在函数中,但我只需传递id事件_53d6e48c65b68。谢谢,有时我们看不到我们在做什么。我们将查找class=actusevent _actuevent_53d6e48c65b68。@Barmar抱歉,根本没有看这个!将立即更新Darren我不需要拆分,但您的代码看起来很好,正如@Barmar在回答中所说的那样我重复了引用中的actus值和函数传递的值我删除了函数的值,它工作得很好
<a href='javascript:void(0)' id="my-link" data-actus-event='53d6e48c65b68' style='float:right;width:24px;height:12px;background:url(http://gomusic.designerbh.com/img/arrow.png) no-repeat bottom center'></a>
$(document).on('click', 'a#my-link', function(e){
    e.preventDefault();
    var actusevent = $(this).data('actus-event');

    $('.actusevent_' + actusevent).hide();
});