开发者

jQuery Mobile : calling JavaScript function

开发者 https://www.devze.com 2023-01-24 22:54 出处:网络
How can I call a JavaScript function while using jQuery Mobile?开发者_如何学JAVAJust like you would any other JavaScript function (considering jQuery IS JavaScript):

How can I call a JavaScript function while using jQuery Mobile?开发者_如何学JAVA


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

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

myFunction(myValue, myOtherValue);


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消