Javascript 在一个脚本中使用多个函数
我知道这个问题可能问得不多,但我找不到适合我的东西 我想把两个脚本整合成一个脚本,但我没有任何运气。正确的方法是什么 脚本:Javascript 在一个脚本中使用多个函数,javascript,jquery,Javascript,Jquery,我知道这个问题可能问得不多,但我找不到适合我的东西 我想把两个脚本整合成一个脚本,但我没有任何运气。正确的方法是什么 脚本: $('document').ready( function() { function _title() { var allow = document.title.search("Inloggen / Infotheek Portal -"); if (allow > -1) {
$('document').ready(
function() {
function _title() {
var allow = document.title.search("Inloggen / Infotheek Portal -");
if (allow > -1) {
window.location.assign("http://ccp.infotheek.com/m4n?oid=etailer-status")
}
}
window.onload = _title;
});
$('document').ready(
function() {
function _title() {
var allow = document.title.search("Infotheek Portal -");
if (allow > -1) {
document.getElementById('newbutton').style.display = "block";
}
}
window.onload = _title;
});
无需分配给
窗口。onload
处理程序,只需在文档就绪时执行所有逻辑即可
$(document).ready(function() {
var allow = document.title.search("Inloggen / Infotheek Portal -");
if(allow>-1) {
window.location.assign("http://ccp.infotheek.com/m4n?oid=etailer-status")
}
allow = document.title.search("Infotheek Portal -");
if(allow>-1){
document.getElementById('newbutton').style.display="block";
}
});
如果确实要在窗口.onload中运行此操作,则只需替换以下行:
$(document).ready(function() {
为此:
$(window).on('load', function() {
if(条件#1){do stuff for#1}else if(条件#2){do stuff for#2}
^^^好建议。或者将其中一个函数名从_title更改为_title2或任何您想调用的名称。如果他有其他调用函数_title的代码怎么办?他的函数_title()
在$(document).ready()
函数作用域中本地声明,因此在该上下文之外不可用。