[英]Multiple document.ready not working how to combine them to make a single document.ready
jQuery(document).ready(function(a) {
a("body").scrollspy({
target: ".bs-sidebar",
offset: 0
}),
a(window).on("load", function() {
a("body").scrollspy("refresh")
}), setTimeout(function() {
var b = a(".bs-sidebar");
b.affix({
offset: {
top: function() {
var a = b.offset().top,
c = parseInt(b.children(0).css("margin-top"), 10);
return this.top = a - c
},
bottom: function() {
return this.bottom = a(".bs-footer").outerHeight(!0)
}
}
})
}, 100), a(".token-example-field").tokenfield(),
a("#tokenfield-1").tokenfield({
autocomplete: {
source: outp,
delay: 100
},
showAutocompleteOnFocus: !0,
delimiter: [",", " ", "-", "_"]
});
var b = new Bloodhound({
local: loutp,
datumTokenizer: function(a) {
return Bloodhound.tokenizers.whitespace(a.value)
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
b.initialize(), a("#tokenfield-typeahead").tokenfield({
typeahead: [null, {
source: b.ttAdapter()
}]
}), a("#tokenfield-1").on("tokenfield:createtoken",
function(a) {
var b = a.attrs.value.split("|");
a.attrs.value = b[1] || b[0], a.attrs.label = b[1] ? b[0] + " (" + b[1] + ")" : b[0]
}).on("tokenfield:createdtoken",
function(b) {
var c = /\S+@\S+\.\S+/,
d = c.test(b.attrs.value);
d || a(b.relatedTarget).addClass("invalid")
}).on("tokenfield:edittoken",
function(a) {
if (a.attrs.label !== a.attrs.value) {
var b = a.attrs.label.split(" (");
a.attrs.value = b[0] + "|" + a.attrs.value
}
}).on("tokenfield:removedtoken",
function(b) {
if (b.attrs.length > 1) {
var c = a.map(b.attrs, function(a) {
return a.value
});
alert(b.attrs.length + " tokens removed! Token values were: " + c.join(", "))
} else alert("Token removed! Token value was: " + b.attrs.value)
}).tokenfield()
});
jQuery(document).ready(function(a) {
a("body").scrollspy({
target: ".bs-sidebar",
offset: 0
}), a(window).on("load", function() {
a("body").scrollspy("refresh")
}), setTimeout(function() {
var b = a(".bs-sidebar");
b.affix({
offset: {
top: function() {
var a = b.offset().top,
c = parseInt(b.children(0).css("margin-top"), 10);
return this.top = a - c
},
bottom: function() {
return this.bottom = a(".bs-footer").outerHeight(!0)
}
}
})
}, 100),
a(".token-example-field").tokenfield(), a("#tokenfield-3").tokenfield({
autocomplete: {
source: outp,
delay: 100
},
showAutocompleteOnFocus: !0,
delimiter: [",", " ", "-", "_"]
});
var b = new Bloodhound({
local: loutp,
datumTokenizer: function(a) {
return Bloodhound.tokenizers.whitespace(a.value)
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
b.initialize(), a("#tokenfield-typeahead").tokenfield({
typeahead: [null, {
source: b.ttAdapter()
}]
}),
a("#tokenfield-3").on("tokenfield:createtoken", function(a) {
var b = a.attrs.value.split("|");
a.attrs.value = b[1] || b[0], a.attrs.label = b[1] ? b[0] + " (" + b[1] + ")" : b[0]
})
.on("tokenfield:createdtoken", function(b) {
var c = /\S+@\S+\.\S+/,
d = c.test(b.attrs.value);
d || a(b.relatedTarget).addClass("invalid")
}).
on("tokenfield:edittoken", function(a) {
if (a.attrs.label !== a.attrs.value) {
var b = a.attrs.label.split(" (");
a.attrs.value = b[0] + "|" + a.attrs.value
}
}).
on("tokenfield:removedtoken", function(b) {
if (b.attrs.length > 1) {
var c = a.map(b.attrs, function(a) {
return a.value
});
alert(b.attrs.length + " tokens removed! Token values were: " + c.join(", "))
} else alert("Token removed! Token value was: " + b.attrs.value)
}).tokenfield()
});
jQuery(document).ready(function(a) {
a("body").scrollspy({
target: ".bs-sidebar",
offset: 0
}), a(window).on("load", function() {
a("body").scrollspy("refresh")
}), setTimeout(function() {
var b = a(".bs-sidebar");
b.affix({
offset: {
top: function() {
var a = b.offset().top,
c = parseInt(b.children(0).css("margin-top"), 10);
return this.top = a - c
},
bottom: function() {
return this.bottom = a(".bs-footer").outerHeight(!0)
}
}
})
}, 100), a(".token-example-field").tokenfield(), a("#tokenfield-4").tokenfield({
autocomplete: {
source: outp,
delay: 100
},
showAutocompleteOnFocus: !0,
delimiter: [",", " ", "-", "_"]
});
var b = new Bloodhound({
local: loutp,
datumTokenizer: function(a) {
return Bloodhound.tokenizers.whitespace(a.value)
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
b.initialize(), a("#tokenfield-typeahead").tokenfield({
typeahead: [null, {
source: b.ttAdapter()
}]
}), a("#tokenfield-4").on("tokenfield:createtoken", function(a) {
var b = a.attrs.value.split("|");
a.attrs.value = b[1] || b[0], a.attrs.label = b[1] ? b[0] + " (" + b[1] + ")" : b[0]
}).on("tokenfield:createdtoken", function(b) {
var c = /\S+@\S+\.\S+/,
d = c.test(b.attrs.value);
d || a(b.relatedTarget).addClass("invalid")
}).on("tokenfield:edittoken", function(a) {
if (a.attrs.label !== a.attrs.value) {
var b = a.attrs.label.split(" (");
a.attrs.value = b[0] + "|" + a.attrs.value
}
}).on("tokenfield:removedtoken", function(b) {
if (b.attrs.length > 1) {
var c = a.map(b.attrs, function(a) {
return a.value
});
alert(b.attrs.length + " tokens removed! Token values were: " + c.join(", "))
} else alert("Token removed! Token value was: " + b.attrs.value)
}).tokenfield()
});
根据文档,我可以向您保证多个document.ready函数正在运行...
$(document).ready(function() {
alert("test1!");
});
$(document).ready(function() {
alert("test2!");
});
看到这个小提琴:
无论如何,如果您真的要问“如何组合”,o-将它们全部放在一个函数体中...
样品:
$(document).ready(function() {
alert("test1!");
alert("test2!");
});
如您在第一个示例中看到的,两个document.ready()都被调用,因此您的脚本中必须存在一个可能导致运行时错误的错误,这可能是一个不存在的变量或对象,因为它在“ if”内部是斜体,一个null对象,一个无效的数组索引。
如果您需要任何帮助,请提供该页面正常工作所需的HTML输出,并可能为此创建一个示例小提琴,并简短地向我们解释其应做的事情,然后我们可以检查其为什么不起作用您期望它做什么。
但是,您的线程主题已得到回答,并被证明是错误的。
$result = $conn->query("SELECT cname from country");
$outp = "[";
$loutp="[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp =$outp.''.$rs["cname"].'';
if ($loutp != "[") {$loutp .= ",";}
$loutp=$loutp.'{value:'.'"'.$rs["cname"].'"}';
}
$outp .="]";
$loutp.="]";
谢谢所有我解决我的问题jQuery代码未执行完毕,因为loutp是字符串,但是需要对象代替字符串,因此我使用eval(loutp)进行了转换; 现在,jquery完全执行并且现在可以正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.