我的jquery doc ready函数无法识别外部js文件函数?(My jquery doc ready function doesn't recognize an external js

编程入门 行业动态 更新时间:2024-10-19 21:26:01
我的jquery doc ready函数无法识别外部js文件函数?(My jquery doc ready function doesn't recognize an external js file function?)

当我将它们放在与HTML内容相同的页面上时,我创建了几个正常工作的函数,但由于开始有这么多函数,我决定将它们移动到.js文件中。 现在无法调用初始函数。

IE8说这个功能不存在。 我已确认链接正确并确认js文件正在加载。 我甚至将初始化的触发事件链接到一个按钮(使用loadFile类),因此我可以手动触发它以确保它不是加载的时间。 我在这里做错了什么?

以下是外部脚本和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>

这是我的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(); }

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. Now the initial function cannot be called.

IE8 is saying the function doesn't exist. I have confirmed the link is correct and confirmed the js file is loading. 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. 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:

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(); }

最满意答案

如果没有看到如何构建页面其余部分的完整上下文,则很难完全诊断。

我要检查的是确保在上面的任何代码之前你被称为jquery.js,否则它不会设置你所追求的任何事件。 您是否尝试过使用firebug并检查控制台是否报告任何其他JavaScript错误。

你说你的配置需要你以一种不寻常的方式调用外部JS文件 - 我假设文件在某种程度上被解析然后将其转换为普通链接? 如果是这样,之后HTML会是什么样子?

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. Have you tried using firebug and checking the console to see if it is reporting any other JavaScript errors.

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? If so, what does the HTML look like after that?

更多推荐

本文发布于:2023-07-24 00:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   无法识别   文件   jquery   ready

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!