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

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

问题描述

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

我不想放

data-ajax = false

每次我不想使用jquerymobile ajax.

例如,任何属于内容"子项的链接:

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

我想将'data-ajax = false'添加到作为'content'子级的每个链接上

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

解决方案

如果要通过锚标记禁用ajax链接行为,则可以在链接中放入rel=external,并且该链接将在没有ajax和您的url的情况下加载然后会很正常.

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>

如果您要在jQuery中针对内容div中的一些a标签执行此操作,则可以尝试这样

$(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天全站免登陆