使用 jQuery Mobile 从常规链接中删除 ajax 调用 [英] Remove ajax call from regular links with jQuery Mobile

查看:23
本文介绍了使用 jQuery Mobile 从常规链接中删除 ajax 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jQuery Mobile 我想禁用对 DOM 特定部分内的链接的 ajax 调用.

我不想放

data-ajax = false

每次我都不想使用 jquerymobile ajax.

例如,作为内容"子项的任何链接:

<a href="http://externalwebsite.com">外部链接</a>

我想将data-ajax = false"添加到作为内容"子项的每个链接上

有没有办法用 jquery 做到这一点?

解决方案

如果你想禁用锚标签的ajax链接行为,你可以在链接和链接中加入rel=external将在没有 ajax 的情况下加载,然后您的网址将是正常的.

http://jquerymobile.com/demos/1.0a4.1/#docs/pages/docs-navmodel.html

<a href="User/somepage" rel="external"/>我不会使用 ajax 进行导航</a>

如果您想在 jQuery 中为内容 div 中的某些标签执行此操作,您可以尝试这样

$(function(){$(".content a").each(function(){$(this).attr("rel","external");});});

这是一个示例 http://jsfiddle.net/4WEBk/3/>

更简化的版本.(感谢 tandu 指点)

$(function(){$(".content a").attr("rel","external");});

Using jQuery Mobile I would like to disable the ajax call on links within a specific part of the DOM.

I do not want to put a

data-ajax = false

every time I don't want to use the jquerymobile ajax.

For example, any link that is a child of 'content':

<div class="content">
    <a href="http://externalwebsite.com">External Link</a>
</div>

I would like to add the 'data-ajax = false' onto every link that is a child of 'content'

Is there a way to do this with jquery?

解决方案

If you want to disable the ajax link behaviour from an anchor tag, you can put rel=external in the link and the link will load without ajax and your url will then be usual.

http://jquerymobile.com/demos/1.0a4.1/#docs/pages/docs-navmodel.html

<a href="User/somepage" rel="external" />I wont be using ajax for navigation</a>

If you want to do this in jQuery for some a tags inside content div, you may try like this

$(function(){
  $(".content a").each(function(){
    $(this).attr("rel","external");
  });
});

Here is a sample http://jsfiddle.net/4WEBk/3/

The more Simplified version. (Thanks to tandu for pointing )

$(function(){
  $(".content a").attr("rel","external");
});

这篇关于使用 jQuery Mobile 从常规链接中删除 ajax 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆