Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击事件后的未捕获异常_Javascript_Jquery - Fatal编程技术网

Javascript 单击事件后的未捕获异常

Javascript 单击事件后的未捕获异常,javascript,jquery,Javascript,Jquery,所以我得到了这个jQuery代码: //some button var moreButton = $('<a href="#" class="buttonClass">Szczegóły</a>'); //load button to the first element with given class $('.someDiv').first().append(moreButton); //after button click we show/hide anoth

所以我得到了这个jQuery代码:

//some button
var moreButton = $('<a href="#" class="buttonClass">Szczegóły</a>'); 

//load button to the first element with given class
$('.someDiv').first().append(moreButton); 

//after button click we show/hide another div

$(moreButton).on('click', function(e){
    e.preventDefault();
    $('.hiddenDiv').slideToggle();    
});
单击事件之后


我已尝试从单击功能中删除所有内容,只留下一些console.log,但问题仍然存在。

您的代码错误。。应该是这样的:

//some button
var moreButton = '<a style="cursor: pointer" class="buttonClass">Szczegóły</a>'; 

嗯。它与其他代码冲突

有趣的是,Safari开发工具比Firebug更有用

jQuery.noConflict();
(function( $ ) {
  $(function() {
    // More code using $ as alias to jQuery
  });
})(jQuery);

var$$=$.noConflict(true);
//一些按钮
var moreButton=$$(“”{
'href':“#”,
“类”:“按钮类”,
“文本”:“Szczegóły”
});
//将按钮加载到具有给定类的第一个元素
$$('.someDiv').first().append(moreButton);
//单击按钮后,显示/隐藏另一个div
$$(更多按钮)。在('单击')上,函数(e){
e、 预防默认值();
$$('.hiddenDiv').slideToggle();
});

在哪一行引发异常?这也可能是anchorCan not reproduction->中的unicode字符的问题,jQuery不会抛出这样的错误!还有别的事情在起作用。其他库或其他代码。您需要将页面裁剪到最低限度,看看是什么导致了问题。我认为问题可能来自于通过Ajax加载的“.hiddenDiv”,但该按钮是在Ajax调用完成后追加的。整个滑动功能工作正常。控制台没有给出任何关于问题发生地点的提示。没关系,除非它被多次包装,即使你做了
$($(…)
,它仍然会。
$('.buttonClass').on('click', function(e){
    e.preventDefault();
    $('.hiddenDiv').slideToggle();    
});
jQuery.noConflict();
(function( $ ) {
  $(function() {
    // More code using $ as alias to jQuery
  });
})(jQuery);
var $$ = $.noConflict(true);
//some button
var moreButton = $$("<a>",{
    'href': "#",
    'class':"buttonClass",
    'text':"Szczegóły"
});

//load button to the first element with given class
$$('.someDiv').first().append(moreButton);

//after button click we show/hide another div

$$(moreButton).on('click', function(e){
    e.preventDefault();
    $$('.hiddenDiv').slideToggle();
});