Access jQuery Mobile page content (under) using JavaScript

I'm trying to use many standard JavaScript DOM functions to access elements in an HTML document ( getElementById, getElementsByNameetc.), but I can't get it to work with jQuery Mobile - when the subpage loads, the values ​​returned from getElementById("elementOfInterest").innerHTMLstill contain the value on main page.

I am trying to implement this in an iPhone application in order to retrieve and display the headers of the corresponding subpages in the navigation bar (the page is displayed in UIWebView), but I think (and hope) that the problem and solution is more or less "platform independent".

Anyone with thoughts on how to achieve this using JavaScript (or maybe some jQuery function)? However, I could not find anything in jQuery mobile docs.

+3
source share
1 answer

According to the jQuery Mobile configuration behavior , it will automatically process links and submit forms via Ajax whenever possible. Therefore, when you open a new page (subpage), a new page will be added to the DOM main page. During this time, you will lose JavaScript written on a new page.

According to my thinking, you can disable the Ajax form and link.

To do this, write the link as follows:

<a href="createForm.htm" data-role="button" data-ajax="false">Create</a>

, :

<script src="/js/jquerymobile/jquery-1.5.min.js"></script>
<script type="text/javascript">
    $(document).bind("mobileinit", function(){
        $.mobile.ajaxEnabled= false;
    });
</script>
<link rel="stylesheet" href="/css/jquerymobile/jquery.mobile-1.0a3.min.css" />
<script src="/js/jquerymobile/jquery.mobile-1.0a3.min.js"></script>

, , !

: http://jquerymobile.com/demos/1.0a3/#page.html&subpageidentifier

Edit:

, , :

<div data-role="header">
    <a href="../list.htm" data-icon="arrow-l" data-ajax="false">Back</a>
    <h1>
        List items
    </h1>
</div>
+2

Source: https://habr.com/ru/post/1791570/


All Articles