JQ触摸和AJAX
我对此有点陌生,所以如果我有点含糊,我很抱歉,但我会尽力而为。
我正在尝试使用 JQtouch 创建一个 iphone 友好版本的网站。据我所知,通常这将在一个 HTML 文件中完成,其中页面由 DIV 分隔。但是,我想从网站的现有页面加载内容。
问题的下一部分是我的 iphone.html 页面与我当前的网站不在同一目录中,因此 JQtouch 的正常行为似乎不起作用。
到目前为止,我已经设置了一个页面,如下所示:
<div id="home">
<div class="toolbar">
<h1>Title</h1></div>
<ul class="rounded">
<li class="arrow"> <a href="#content">HOME</a></li>
<li class="arrow"> <a href="#about">ABOUT US</a></li>
<li class="arrow"> <a href="#gnwr">GNWR</a></li>
<li class="arrow"> <a href="#gner">GNER</a></li>
<li class="arrow"> <a href="#journal">NEWS</a></li>
<li class="arrow"> <a href="#FAQS">FAQS</a></li>
<li class="arrow"> <a href="#contact">CONTACT</a></li>
</ul>
</div>
<div id="content"></div>
<div id="about"></div>
<div id="journal"></div>
<div id="faqs"></div>
<div id="contact"></div>
</body>
</html>
然后我有:
<script>
$(document).ready(function(){
$('#content').load('http://www.mysite.co.uk' + ' #content');
$('#about').load('http://www.mysite.co.uk/about' + ' #content');
}
</script>
这会加载我想要的内容,并且页面动画工作正常。唯一的问题是,我正在加载的内容中存在几个链接,当单击它们时,它们显然不起作用。
有没有办法可以在单击链接时检查链接的 href,如果它指向 www.mysite.co.uk/about,则将其更改为指向 #about 并强制它导航到那里?
希望这是有意义的,如果您需要更多信息,请告诉我。
问候
克里斯。
I am a little new to this so apologies if I am a little vaugue but I will do my best.
I am attempting to create an iphone friendly version of a site using JQtouch. I understand that normally this would be done all in one HTML file with pages seperated by DIV's. However, I am wanting to load the content from exisitng pages of a website.
The next part to the problem is that my iphone.html page does not sit in the same directory as my current website, so the normal behaviour of JQtouch doesnt seem to work.
So far I have set up a page as follows:
<div id="home">
<div class="toolbar">
<h1>Title</h1></div>
<ul class="rounded">
<li class="arrow"> <a href="#content">HOME</a></li>
<li class="arrow"> <a href="#about">ABOUT US</a></li>
<li class="arrow"> <a href="#gnwr">GNWR</a></li>
<li class="arrow"> <a href="#gner">GNER</a></li>
<li class="arrow"> <a href="#journal">NEWS</a></li>
<li class="arrow"> <a href="#FAQS">FAQS</a></li>
<li class="arrow"> <a href="#contact">CONTACT</a></li>
</ul>
</div>
<div id="content"></div>
<div id="about"></div>
<div id="journal"></div>
<div id="faqs"></div>
<div id="contact"></div>
</body>
</html>
I then have :
<script>
$(document).ready(function(){
$('#content').load('http://www.mysite.co.uk' + ' #content');
$('#about').load('http://www.mysite.co.uk/about' + ' #content');
}
</script>
This loads the content I am after and the page animations work fine. The only problem is that a couple of links exist in the content I am loading and when clicked they obviously dont work.
Is there a way I can check the href of a link when clicked and if it points to www.mysite.co.uk/about change it to point to #about and force it to navigate there?
Hope this makes sense if you need more info let me know.
Regards
Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在一个问题中提出了很多问题......您确实应该将它们分成几个问题。人们更容易回答。无论如何,我会尝试一下。
首先,你不必将所有内容都放在一个 html 中;您可以通过 AJAX 加载内容。请参阅 AJAX > 此演示中的“GET 示例”,以及 页面内容通过AJAX加载。
据我所知,您要加载的页面不必位于同一目录结构中。您想要通过 AJAX 加载的页面需要包含有效的 jQTouch 页面,即整个页面包含在
中。
如果我理解正确的话,您本质上是想将
www.mysite.co.uk/about
的所有链接替换为#about
。这必须使用 jQuery 来完成:您可能希望在每个页面加载时执行此操作:
You are asking quite a few questions inside a single question... You should really break them up into several questions. It's easier for people to answer. Anyways, I'll give it a shot.
First of all, you don't have to have all contents in one html; you can load contents via AJAX. See the AJAX > "GET Example" in this demo, as well as the page content loaded via AJAX.
As far as I know, the pages you want to load do not have to be in the same directory structure. The pages you want to load via AJAX need to contain a valid jQTouch page, i.e. the whole page is enclosed in a
<div>
.If I understand you correctly, you essentially want to replace all the links to
www.mysite.co.uk/about
with#about
. This has to be done with jQuery:You may want to do that when each page loads: