开发者

how can call a html page div from javascript?

I am working on phonegap with android. I am creating a login page. After the login validation I want to jump to the welcome div if the user is authorized .

This is my javascript page:- myjavascrpt.js

   var logi=item.id;   
   if(logi>0)
   call welcome div of index.html
    else
    alert("invalid user"); 

                       // in this logi variable i have userid of successful user.
                       // now i want to  
                        // display this id into the div which is exist in my 
                        // html page.
                        // now what should i write here so i can call welcome 
                        // div of html page and i can use 
                        // this value of logi variable.
开发者_运维知识库

This is my index.html whose welcome div I want to call.

    <html>
      <head></head>
      <body>
        <div data-role="page" data-theme="a" data-url="streaming" id="streaming">
             <h1> do some thing related to streaming</h1>
        </div>  
        **
        <div data-role="page" data-theme="a" data-url="welcome" id="welcome">
        <h1> you are welcome</h1>
        </div>
        **
      </body>
    </html>

so please tell me what code should I use to call the div of a html page.


I don't know anything about calling a html page div from javascript, but if you want to set the content of a DIV via javascript, it's done that way:

In javascript:

var d = document.getElementByID("welcome");
d.innerHTML = logi;

But this would override the <h1> you are welcome</h1> text. So change that line to be

<span id="userwelcome"></span><h1>, you are welcome</h1>

and your javascript to

var d = document.getElementByID("userwelcome");
d.innerHTML = logi;


You can do that with simple jQuery -

if(logi>0) { $('#welcome').html(logi);}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜