2017-02-15 39 views
0

这是以前的工作为我好,但我认为有些事情改变了如何jQuery是在WordPress正在排队。

$(document).ready(function() { 

$('#dialog-modal').dialog({ 
    modal: true, 
    autoOpen: false, 
    closeOnEscape: false, 
    bgiframe: true, 
    title: 'Please Confirm', 
    buttons: { 
      "Ok!": function() { 
        $(this).dialog("close"); 
      } 
    } 
}); 

$("[name='records']").on('change',function(e){ 
var selectedValue = $(this).val(); 
if(selectedValue==2) { 

     $('#dialog-modal').dialog('open'); 
    } 
}); 

}); 

我的控制台显示:

遗漏的类型错误:$不是一个函数

我提到了这个问题:

TypeError: $ is not a function when calling jQuery function

但我仍然不知道如何正确包装。

+0

你有排队的jQuery库在页面或标题? –

回答

0

您分配$ jQuery的是这样的:

/** 
* 
* Description 
* 
*/ 

(function(window, $, undefined) { 

    'use strict'; 


    $(document).ready(function() { 

     //what is this            
     $('#dialog-modal').dialog({ 
      modal: true, 
      autoOpen: false, 
      closeOnEscape: false, 
      bgiframe: true, 
      title: 'Please Confirm', 
      buttons: { 
       "Ok!": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 


     // what is this 
     $("[name='records']").on('change',function(e){ 
      var selectedValue = $(this).val(); 
      if(selectedValue==2) { 

       $('#dialog-modal').dialog('open'); 
      } 
     }); 



    }); //* end ready 


})(this, jQuery); 
+0

这并不显示任何控制台错误,但它不再激发模式。我怀疑,我是使用jQuery之前的新版本和WordPress的的版本(的jquery.js?版本= 1.12.4),是不是跟这个工作。令人沮丧。我想我必须做更多的挖掘。我会跟进。 –

+0

您也可以注册主脚本,而不仅仅是排队,然后调用依赖,当你排队此脚本。 – Christina

+0

谢谢。幸运的是我有一个工作备份。我还缺少jquery-ui.css,它在脚本修复后阻止了模态的出现。您的解决方案奏效 –

0

尝试的jQuery,而不是$。 WordPress的一般refences它作为jQuery的

由于这样的:

jQuery(document).ready(function() { 

jQuery('#dialog-modal').dialog({ 
    modal: true, 
    autoOpen: false, 
    closeOnEscape: false, 
    bgiframe: true, 
    title: 'Please Confirm', 
    buttons: { 
      "Ok!": function() { 
        jQuery(this).dialog("close"); 
      } 
    } 
}); 

jQuery("[name='records']").on('change',function(e){ 
var selectedValue = $(this).val(); 
if(selectedValue==2) { 

     jQuery('#dialog-modal').dialog('open'); 
    } 
}); 

}); 

我希望这个作品,,

+0

我最初尝试过,但正如我上面的评论所述,目前我不能确切地说。我要重新检查我以前的版本,看看现在是否是这个问题。 –