简体   繁体   English

我的jQuery文档准备功能无法识别外部js文件功能?

[英]My jquery doc ready function doesn't recognize an external js file function?

I created several functions that were working properly when I had them on the same page as the HTML content, but because there started to be so many functions I decided to move them over to a .js file. 当我将它们与HTML内容放在同一页面上时,我创建了几个可以正常工作的函数,但是由于开始有太多的函数,我决定将它们移至.js文件。 Now the initial function cannot be called. 现在无法调用初始函数。

IE8 is saying the function doesn't exist. IE8表示该功能不存在。 I have confirmed the link is correct and confirmed the js file is loading. 我已确认链接正确,并确认正在加载js文件。 I have even linked the trigger event for the initialization to a button (with the class of loadFile) so I can manually trigger it to ensure it's not the timing of loading. 我什至将初始化的触发事件链接到了一个按钮(带有loadFile类),因此我可以手动触发它以确保它不是加载时间。 I am doing something wrong here? 我在这里做错了吗?

Here is the link to the external script and the doc ready: 这是指向外部脚本和文档的链接:

//This is how we must reference external files in our configuration, 
//but this is correct, and I am certain this is not the problem.
<script src="<#=getManagedWebFileRelativePath('docAttachmentIE8.js') #>"></script>

<script type="text/javascript">
    $(document).ready(function(){          
        $('.loadFile').click(function() {                   
            initializeDocAttachments(); 
        });
    }); // END DOC Ready           
</script>

Here is an extract from my js file: 这是我的js文件的摘录:

function initializeDocAttachments() {
    //for IE8 load this form
    var docFormHTML = "<form method='POST' id='frmUploadDoc' enctype='multipart/form-data' action=''>\
                       <input type='file' name='data' onchange='handleFileSelect(this);' id='filesInput'>&nbsp;&nbsp; Upload a file</form>";
    document.getElementById('docAttachmentControl').innerHTML = docFormHTML;               
    docLoadDocs();
}   

What you have makes sense and works when I put the code in this fiddle: http://jsfiddle.net/3PtuH/1 当我将代码放入此小提琴中时,您所拥有的才有意义并可以正常工作: http : //jsfiddle.net/3PtuH/1

What is the exact error message you are getting? 您得到的确切错误消息是什么? IS IE8 saying that the initializeDocAttachments() function doesn't exist? IE8是否说initializeDocAttachments()函数不存在? Could it be possible that it's saying the inner docLoadDocs() function might not exist? 是否可能说内部docLoadDocs()函数可能不存在?

Without seeing the full context of how the rest of the page is constructed it will be hard to fully diagnose. 如果没有看到页面其余部分的构造方式的完整上下文,将很难完全诊断出来。

Things I would check is to make sure you are called jquery.js before any of the code above otherwise it wont setup any of the events you're after. 我要检查的事情是确保在上面的任何代码之前都将您称为jquery.js,否则它将不会设置您所关注的任何事件。 Have you tried using firebug and checking the console to see if it is reporting any other JavaScript errors. 您是否尝试过使用Firebug并检查控制台以查看其是否报告了任何其他JavaScript错误。

You say your configuration needs you to call the external JS file in an unusual way - I assume file gets parsed in someway which then translates it to a normal link? 您说您的配置需要您以一种不寻常的方式调用外部JS文件-我假设文件以某种方式被解析,然后将其转换为普通链接? If so, what does the HTML look like after that? 如果是这样,那么之后的HTML是什么样的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM