jQuery data-ajax="false" 到底有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13357088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:33:22  来源:igfitidea点击:

What does data-ajax="false" really do?

jqueryhtmlajaxjquery-mobile

提问by Dan Ovidiu Boncut

The links on my site don't work and I got an solution of using data-ajax="false"on my anchors without getting a true explanation. Can someone help me?

我网站上的链接不起作用,我得到了一个data-ajax="false"在我的锚上使用的解决方案,但没有得到真正的解释。有人能帮我吗?

回答by MrCode

data-ajaxis a feature of jQuery Mobile. JQM by default will try to load pages via ajax for improved user experience and transitions. If you set data-ajax='false'then JQM will do a normal page request instead of using ajax. This can be used on forms as well as links.

data-ajax是 jQuery Mobile 的一个特性。默认情况下,JQM 将尝试通过 ajax 加载页面以改善用户体验和转换。如果您设置,data-ajax='false'那么 JQM 将执行普通页面请求而不是使用 ajax。这可以用于表单和链接。

From the docs:

文档

This tells the framework to do a full page reload to clear out the Ajax hash in the URL

这告诉框架重新加载整个页面以清除 URL 中的 Ajax 哈希

If you want to disable ajax on all of your links then instead of adding data-ajaxto everything, you can do it like this:

如果你想在你的所有链接上禁用 ajax,而不是添加data-ajax到所有链接,你可以这样做:

$(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
});

回答by Quentin

Nothing at all.

什么都没有。

data-*is a generic set of attributes that you can store data in for access by JavaScript.

data-*是一组通用属性,您可以在其中存储数据以供 JavaScript 访问。

Unless you have some JavaScript that deals with them, they are meaningless.

除非你有一些处理它们的 JavaScript,否则它们是没有意义的。

jQuery has nothing built in that does anything with them.

jQuery 没有内置任何东西可以对它们做任何事情。

回答by pocesar

if you set the attribute of an element to data-name, you can, through jQuery, fetch it using $('element').data('name')instead of $('element').attr('data-name');, but data-*attributes can still be used for event delegation, like $(document).on('click', '[data-name]', function(){});

如果将元素的属性设置为 data-name,则可以通过 jQuery 使用$('element').data('name')代替来获取它$('element').attr('data-name');,但是data-*属性仍然可以用于事件委托,例如$(document).on('click', '[data-name]', function(){});