WebView 无法访问资产中的 jquery 脚本
我正在测试 jquery.mobile 脚本,并且能够使用 WebView 运行 HTML5 内容。
似乎它找不到我的 jquery 文件,但我已将它们相应地放置在以下路径中:
Project >资产> www> jquery
我的html文件所在的
:项目>资产> www> index.html
我的html看起来像这样:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="file:///android_asset/www/jquery/jquery.mobile-1.0.min.css" />
<script src="file:///android_asset/www/jquery/jquery-1.6.4.min.js"></script>
<script src="file:///android_asset/www/jquery/jquery.mobile-1.0.min.js"></script>
<style type="text/css">
#floatMe
{
float: right;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#btnHello').click(function() {
var name = $('#txtName').val();
alert(name);
});
});
</script>
</head>
<body>
<div id="floatMe">
What's your name?
<input id="txtName" value="" />
<button id="btnHello">say hello</button>
</div>
</body>
</html>
错误不断提示我:
ReferenceError:找不到变量:jQuery at file:///android_asset/www/index.html ReferenceError:找不到变量:$ 在 file:///android_asset/www/index.html
I'm testing the jquery.mobile script and was able to run a HTML5 content using WebView.
It seems that it can't find my jquery files but i've placed them accordingly inside the following path:
Project > assets > www > jquery
where my html file is located:
Project > assets > www > index.html
my html looks like this:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="file:///android_asset/www/jquery/jquery.mobile-1.0.min.css" />
<script src="file:///android_asset/www/jquery/jquery-1.6.4.min.js"></script>
<script src="file:///android_asset/www/jquery/jquery.mobile-1.0.min.js"></script>
<style type="text/css">
#floatMe
{
float: right;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#btnHello').click(function() {
var name = $('#txtName').val();
alert(name);
});
});
</script>
</head>
<body>
<div id="floatMe">
What's your name?
<input id="txtName" value="" />
<button id="btnHello">say hello</button>
</div>
</body>
</html>
The error keeps prompting me:
ReferenceError: Can't find variable: jQuery at file:///android_asset/www/index.html
ReferenceError: Can't find variable: $ at file:///android_asset/www/index.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用相对于 HTML 页面的路径?
这就是从 PhoneGap 项目中的页面引用脚本的方式,这应该是类似的,因为它也在 WebView 中运行。
Have you tried using a path relative to your HTML page?
That's how you reference scripts from a page within a PhoneGap project, which should be similar since it's running in a WebView too.