2016-06-10 71 views
0

注意事项:
我没有访问
jQuery是包含在HTML引擎(由发动机渲染)(这就是为什么我不包括在我的代码)得到一个类型错误功能不存在错误

此代码需要一个链接并将其注入到HTML:从代码

$(document).ready(function(){ 
    addSS('https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); 
    addScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'); 
    addScript('//InjectedHTML.js'); 
}); 

function addScript(str){ 
    var script = document.createElement('script'); 
    script.src = str; 
    document.head.appendChild(script); 
}; 

function addSS(str){ 
    var link = document.createElement('link'); 
    link.rel= 'stylesheet'; 
    link.href = str; 
    link.type= 'text/css'; 
    document.head.appendChild(link); 
}; 

InjectedHTML把日期选择到HTML(在一个单独的文件上面):

$(document).ready(function() { 
    addClass();       //adds class attribute to an input that allows me to use datepicker function 
    datePicker();      //adds calendar 
}); 
function addClass(){ 
    $("#DateWrapper input").attr("class", "datepicker"); 
}; 

function datePicker(){ 
    $(".datepicker").datepicker(); 
}; 

收到此错误:
InjectedHTML.js:35遗漏的类型错误:$(...)日期选择器是不是一个函数

感谢您的帮助!

+0

这可能会帮助你:http://stackoverflow.com/quest离子/ 14328762/jquery-ui-loaded-event –

+0

检查你的js路径是否正确 –

+0

JS路径是正确的。 – juice

回答

1

自从我查看手动将脚本加载到DOM的状态以来,已经有几年了,但通常会有一个loaded事件的变体,在脚本实际完成加载时触发。

一般来说,这个过程有些异步,因为它必须去取文件。这意味着在发生这种情况时,他们很可能不会停止执行JavaScript引擎。这意味着你以某种形式看待回调。

有这样做的各种库。如果您不想使用它们,请阅读源代码并调查您定位的平台的要求。

这样的东西:

看起来像jQuery甚至有某种形式的这个:https://api.jquery.com/jquery.getscript/

相关问题