我可以在Documents目录中访问jquery和cordova在应用程序包中创建一个html文件? [英] Can i make a html file in Documents directory which accesses jquery and cordova in the app bundle?
问题描述
我正在建立一个存储在
[[PROJ UserDirectory] stringByAppendingPathComponent:@"tmp_Form_File.html"]
并且正在动态构建文件tmp_FOrm_File.html的内部。身体正确显示,但JS不会执行。
and inside of the file "tmp_FOrm_File.html" it is being dynamically built. Body shows up correctly but the JS will not execute.
我试图做:
NSString * cordova_path = [[NSBundle mainBundle] oathForResource:@"cordova-2.2.0" ofType:@"js" inDirectory:@"html"]
NSString = [[@"<script type=\"text/javascript\" src=\"" stringByAppendingString:cordova_path] stringByAppendingString:@"\"></script>"];
和类似的jquery。
and similarly for jquery.
问题是我不认为当我加载html文件到一个webView它获得相应的数据。
My issue is that i dont think that when I load the htmlfile into a webView that it gets the data accordingly.
我测试了字符串,他们看起来声音:
I tested the strings, and they look sound:
<script type="text/javascript" src="/var/mobile/Applications/[DATA]/PROJ.app/html/cordova-2.2.0.js"></script><script type="text/javascript" src="/var/mobile/Applications/[DATA]/PROJ.app/html/jquery-1.7.2.min.js"></script><script type="text/javascript">$(function(){ alert("test"); });</script>
1)我做错了吗?如果这样,我如何解决这个?
1) Am i doing it wrong? if So, how do i resolve this?
2)更好的通过ios将捆绑包中的html目录复制到文档?如果是,如何?
2) Would it be better to through ios copy the html directory in the bundle to Documents? If so, how?
编辑:临时删除jquery引用,jquery和cordova。只是使用纯javascript,它会正确提醒。所以这意味着src在Bundle中有问题。
推荐答案
但我以这种方式解决:
- 我将[BUNDLE] / html的内容复制到Documents ....
I couldnt reference it atm, but i resolved it this way: - I copied the contents of [BUNDLE]/html to Documents....
NSString * sourcePath = [[[NSBundle mainBundle] pathForResource:@"cordova-2.2.0" ofType:@"js" inDirectory:@"html"] stringByDeletingLastPathComponent];
NSString * documentDirectory = [AssetInspectorFileManager UsersDirectory];
-
调整了javascript的src。
adjusted the src of the javascript.
< script type = \text / javascript \src = \cordova-2.2.0.js \>
< script type=\"text/javascript\" src=\"cordova-2.2.0.js\">
< script type = \text / javascript \src = \jquery-1.7.2.min.js \>>
< script type=\"text/javascript\" src=\"jquery-1.7.2.min.js\">
已关闭缺少父项
$(\div.container\)css(\z-index\,1;
" $(\"div.container\").css(\"z-index\",1;"
成为
" $(\"div.container\").css(\"z-index\",1);"
-
Coomenting是不好的,因为当你写出数据时,如:
Coomenting is not good to do for this, as when you write data out such as:
$(this).click(function(){// [This is A COMMENT] alert(hi);});
$(this).click(function(){//[THIS IS A COMMENT] alert("hi");});
所以你必须调整这种问题。
So you have to adjust for that sort of issue.
这篇关于我可以在Documents目录中访问jquery和cordova在应用程序包中创建一个html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-