添加js等其他文件到IPhone工程中(以添加jquery的js库为例)

本文详细介绍了如何将jQuery集成到iOS应用的UIWebView中。包括将jQuery文件添加为资源、设置Xcode项目的编译配置、在HTML中引用jQuery以及设置正确的baseURL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You might think that if you add the jquery js file to your project, you can build and reference it from html you load into a UIWebView. That’s what I thought too. Here are the steps you need to take.

1. Add the jquery file to resources. Drag the file in, right-click and choose to add an existing file. Whatever you are comfortable with.

Screen shot 2010-04-22 at 4-22-10 9.54.20 AM.png

2. The file will be automatically added as source code. In Xcode under Targets, expand the target you are working on and you’ll find two groups, “Copy Bundle Resources” and “Compile Resources”.

Screen shot 2010-04-22 at 4-22-10 9.55.00 AM.png

3. Drag the file from the “Compile Sources” group

Screen shot 2010-04-22 at 4-22-10 9.55.19 AM.png

to the “Copy Bundle Resources” group.

Screen shot 2010-04-22 at 4-22-10 9.55.42 AM.png

This tells Xcode to package the file up and include it with your app as a resource instead of compiling it.

4. Include the reference to jQuery in your HTML.

html = [NSString stringWithFormat:@"<html><head><script type='text/javascript' src='jquery-1.4.2.min.js'></script></head><body>%@</body></html>", body];

5. Set the baseURL using the path to your jQuery file.

[myWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@”jquery-1.4.2.min.js” ofType:nil]]];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值