WebView 无法访问资产中的 jquery 脚本

发布于 2024-12-27 10:41:11 字数 1240 浏览 2 评论 0原文

我正在测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是在用心讲痛 2025-01-03 10:41:11

您是否尝试过使用相对于 HTML 页面的路径?

<script src="jquery/jquery-1.6.4.min.js"></script>

这就是从 PhoneGap 项目中的页面引用脚本的方式,这应该是类似的,因为它也在 WebView 中运行。

Have you tried using a path relative to your HTML page?

<script src="jquery/jquery-1.6.4.min.js"></script>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文