Php TypeError:$未定义:$.widget(“ui.combobox”){
我在ComboBox中使用jquery,我无法在界面中显示ComboBox。firebug中的错误如下: TypeError:$未定义:$.widget(“ui.combobox”{ 我正在使用以下文件jquery.ui.combobox.js: 代码:Php TypeError:$未定义:$.widget(“ui.combobox”){,php,jquery,combobox,Php,Jquery,Combobox,我在ComboBox中使用jquery,我无法在界面中显示ComboBox。firebug中的错误如下: TypeError:$未定义:$.widget(“ui.combobox”{ 我正在使用以下文件jquery.ui.combobox.js: 代码: $.widget("ui.combobox", { options: { openDialogButtonText: "+", dialogHeaderText: "Add option",
$.widget("ui.combobox", {
options: {
openDialogButtonText: "+",
dialogHeaderText: "Add option",
saveButtonImgUrl: null,
closeButtontext: "Ok"
},
_create: function() {
var selectBox = $(this.element),
id = selectBox.attr("id"),
self = this;
selectBox.addClass("ui-combobox");
// create HTML to inject in the DOM
this.addHtml(id, selectBox);
// turn dialog html into a JQuery UI dialog component
this.addDialog(id);
// @todo set proper button height (roughly equal to select height)
$("#" + id + "-button-opendialog").bind("click", function() {
$("#" + id + "-editor-dialog").dialog("open");
}).button();
$("#" + id + "-button-save").bind("click", function() {
self.addOption(id, selectBox);
}).button();
this._init();
return this;
},
addHtml: function(id, selectBox) {
var imgHtml = "";
if (this.options.saveButtonImgUrl != null) {
imgHtml = '<img src="' + this.options.saveButtonImgUrl + '" alt="opslaan" />';
}
$(' <button id="' + id + '-button-opendialog">' +
this.options.openDialogButtonText +
'</button>' +
'<div id="' + id + '-editor-dialog" class="ui-combobox-editor">' +
'<input id="' + id + '-newitem" type="text" /> ' +
' <button id="' + id + '-button-save">' +
imgHtml + ' Opslaan' +
' </button>' +
'</div>').insertAfter(selectBox);
},
addDialog: function(id) {
var options = this.options;
$("#" + id + "-editor-dialog").dialog( {
autoOpen: false,
modal: true,
overlay: {
opacity:0.5,
background:"black"
},
buttons: {
// @todo make button text configurable
"Ok": function() {
$("#" + id + "-editor-dialog").dialog("close");
return;
}
},
title: options.dialogHeaderText,
hide: 'fold'
});
},
addOption: function(id, selectBox) {
var newItem = $("#" + id + "-newitem");
// @todo do not allow duplicates
if (newItem !== null && $(newItem).val().length > 0) {
// @todo iterate over options and get the highest int value
//var newValue = selectBox.children("option").length + 1;
var highestInt = 0;
selectBox.children("option").each(function(i, n) {
var cInt = parseInt($(n).val());
if (cInt > highestInt) {
highestInt = cInt;
}
});
var newValue = highestInt + 1;
var newLabel = $(newItem).val();
selectBox.prepend("<option value='" + newValue + "' selected='selected'>" + newLabel + "</option>");
this._trigger("addoption", {}, newValue);
// cleanup and close dialog
$(newItem).val("");
$("#" + id + "-editor-dialog").dialog("close");
} else {
this._trigger("addoptionerror", {}, "You are required to supply a text");
}
},
_init: function() {
// called each time .statusbar(etc.) is called
},
destroy: function() {
$.Widget.prototype.destroy.apply(this, arguments); // default destroy
// $(".ui-combobox-button").remove();
// $(".ui-combobox-editor").remove();
}
});
$.widget(“ui.combobox”{
选项:{
openDialogButtonText:“+”,
dialogHeaderText:“添加选项”,
saveButtonImgUrl:null,
closeButtontext:“好的”
},
_创建:函数(){
var selectBox=$(this.element),
id=selectBox.attr(“id”),
self=这个;
selectBox.addClass(“ui组合框”);
//创建要注入DOM的HTML
this.addHtml(id,selectBox);
//将对话框html转换为JQuery UI对话框组件
此.addDialog(id);
//@todo设置适当的按钮高度(大致等于选择高度)
$(“#”+id+“-按钮打开对话框”).bind(“单击”,函数(){
$(“#”+id+“-editor对话框”)。对话框(“打开”);
}).按钮();
$(“#”+id+“-按钮保存”).bind(“单击”,函数(){
self.addOption(id,selectBox);
}).按钮();
这个;
归还这个;
},
addHtml:函数(id,选择框){
var imgHtml=“”;
if(this.options.saveButtonImgUrl!=null){
imgHtml='';
}
$(' ' +
this.options.openDialogButtonText+
'' +
'' +
' ' +
' ' +
imgHtml+“opslan”+
' ' +
'')。插入后面(选择框);
},
addDialog:函数(id){
var options=this.options;
$(“#”+id+“-editor对话框”)。对话框({
自动打开:错误,
莫代尔:是的,
覆盖:{
不透明度:0.5,
背景:“黑色”
},
按钮:{
//@todo使按钮文本可配置
“Ok”:函数(){
$(“#”+id+“-editor对话框”)。对话框(“关闭”);
返回;
}
},
标题:options.dialogHeaderText,
隐藏:“折叠”
});
},
添加选项:功能(id,选择框){
var newItem=$(“#”+id+“-newItem”);
//@todo不允许重复
if(newItem!==null&&$(newItem).val().length>0){
//@todo迭代选项并获得最高的int值
//var newValue=selectBox.children(“选项”).length+1;
var highestInt=0;
selectBox.children(“选项”)。每个(功能(i,n){
var cInt=parseInt($(n).val());
如果(cInt>highestInt){
highestInt=cInt;
}
});
var newValue=最高值+1;
var newLabel=$(newItem).val();
selectBox.prepend(“+newLabel+”);
这个._触发器(“addoption”,{},newValue);
//清理和关闭对话框
$(newItem).val(“”);
$(“#”+id+“-editor对话框”)。对话框(“关闭”);
}否则{
这个.u触发器(“addoptionerror”,{},“您需要提供一个文本”);
}
},
_init:function(){
//每次调用。状态栏(等)被调用
},
销毁:函数(){
$.Widget.prototype.destroy.apply(这个,参数);//默认destroy
//$(“.ui组合框按钮”).remove();
//$(“.ui组合框编辑器”).remove();
}
});
您能帮助我吗?消息“$未定义”意味着调用“$”的函数未在页面的任何位置定义。因此,当执行此代码时,遇到此行时,它不知道该怎么办
$函数是由jQuery定义的。因此,该消息表示在执行代码时它还没有加载jQuery库。这可能有很多原因
看起来页面上没有jQuery。页面上也看不到PHP。请将此附加到头部:
——但是,如果您的页面不在线,但您正在本地运行,请插入
。此外,如果jQuery运行时带有类似这样的舒适警报:if(jQuery){alert],您可以检入javascript文件(“jQuery已加载”);}