简体   繁体   中英

error in converting js code to jQueryMobile

I have a javascript/jquery code http://jsfiddle.net/9773D/ for timer.

I am trying to port it to jQuery Mobile code but I am confused about the pageinit,bind,live etc window events.

In the code i see that the error is because some elements in the tick() function are not loaded in DOM before it has been invoked in the code. Can someone help me in correcting my code.

Thanks,

I changed your line to

var timeDisplay = $(".time")[0];

and that fixes it.

Edit:

Adding explanation:

Since you used innerHTML instead of $('.time').html("") , you needed to set timeDisplay to the HTML node, since innerHTML is a property of the node, not the jQuery object that is returned by the selector $('.time') .

Here's a jsfiddle that shows how it could be done in a more jquery'sh way. http://jsfiddle.net/9773D/1/

timedisplay.innerHtml = "" //does not work since timedisplay is a jquery object 
//timedisplay[0] is the html object so on that innerHtml does work

But jquery has the function .html("");

timedisplay.html(""); // is a bit cleaner

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM