jQuery Mobile:调用 JavaScript 函数

发布于 2024-10-01 13:04:49 字数 44 浏览 0 评论 0原文

使用 jQuery Mobile 时如何调用 JavaScript 函数?

How can I call a JavaScript function while using jQuery Mobile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-10-08 13:04:49

就像任何其他 JavaScript 函数一样(考虑 jQuery IS JavaScript):

var myFunction = function(param1, param2){
    // Do some work
}

myFunction(myValue, myOtherValue);

Just like you would any other JavaScript function (considering jQuery IS JavaScript):

var myFunction = function(param1, param2){
    // Do some work
}

myFunction(myValue, myOtherValue);
芸娘子的小脾气 2024-10-08 13:04:49

与在没有 jQuery mobile 的情况下调用 Javascript 函数的方式相同。

The same way you call a Javascript function without jQuery mobile.

世态炎凉 2024-10-08 13:04:49

这不是问题的答案,但它满足了OP的需求。

当 jquery mobile 加载页面时,它是通过 AJAX 获取的,因此不再有 DOMready。另外 - 页面头部的内容未加载。您必须将代码放入文件中并将其链接到所有页面。然后编写 pageshow 事件处理程序。

jquery mobile 加载的页面始终带有 data-url 属性标记。要在页面显示时完成某些操作(就像以前使用 DOMready 一样),您可以:

$("div:jqmData(url='thatone.html')").live('pageshow',function(e){
//stuff
});

并且此定义可以位于主页或外部脚本中的任何位置。它需要加载 jQuery。由于 live 方法,它不需要页面在事件发生之前存在,甚至根本不存在。

This is not an answer to the question, but it adresses the OP needs.

When a page is loaded by jquery mobile, it is fetched with AJAX, so there is no DOMready anymore. Also - the contents of the page's head are not loaded. You have to put your code in a file and link it to all the pages. Then write pageshow event handlers.

Pages that jquery mobile loads in are always tagged with a data-url atribute. To get something done when the page is being displayed (just like it used to be with DOMready) you can:

$("div:jqmData(url='thatone.html')").live('pageshow',function(e){
//stuff
});

And this definition can be anywhere in the main page or in external scripts. It requires jQuery to be loaded. Thanks to the live method it doesn't require the page to exist before the event happens, or even at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文