繁体   English   中英

使用javascript的phonegap中的动态页面

[英]Dynamic page in phonegap using javascript

具有多个动态标题的动态页面

在此页面中,每件事都是动态的,有人可以帮助我或指导我吗?

使其完全动态。

如果我通过一些错误连续调用方法changeMe(e)

E / Web控制台(5341):未捕获的TypeError:对象#在file:///android_asset/www/subpage.html:29上没有方法'insertAdjacentHTML'

我已经开发了一部分

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, target-densitydpi=device-dpi" />

    <script>

        function changeMe(e)
        {
             e.insertAdjacentHTML("beforeEnd","<div id='inner'></div>");
             addHeadings();

        }

        function addHeadings()
        {
             inner.insertAdjacentHTML("beforeEnd","<h3>Title1</h3>");
             InitThumbs();

        }
        function InitThumbs()
        {
            inner.insertAdjacentHTML("beforeEnd","<ul style='background-color:#ffccaa' id='images'></ul>");
            changeLi();

        }

        function changeLi() 
        {
            for(i=0; i<20;i++)
            {
                images.insertAdjacentHTML("BeforeEnd","<li><a href='subpage.html'> <img width='30%' class='photo' src='images/img.png'>adsad</a></li> ");
            }
        }



    </script>

    <style>



        html, body
        {
            margin: 0;
            padding: 0;
            border: 0;
            outline: 0;
            font-size: 100%;
            text-decoration: none;

        }

        ul
        {
            margin: 0;
            padding: 0;
            white-space: nowrap;
            width: 100%;
            overflow-x: auto;
        }

        li 
        {
            display: inline;
        }

        #content 
        {
            height:100%;
        }


        .title
        {
            height:10%;
            width="100%"
            border-bottom-color: #000;
            border-bottom-style: solid;
            border-bottom-width: 1%;                
        }

        .title .center img
        {
            height:100%;       
        }

        .title .left img
        {
            height:100%;   
        }

        .title .right img
        {
            height:100%;       
        }

        .title .center
        {
            height:100%;    
            width:50%;  
            float: left;       
        }
        .title .right
        {
            height:100%;    
            width:25%;  
            float: left;    
            margin:0 auto;
            overflow:hidden;   
        }
        .title .left
        {
            height:100%;
            width:25%;  
            float: left;    
            margin:0 auto;
            overflow:hidden;  
        }

        .outer
        {
            height:90%;             
        }

        a:link,
        a:visited 
        {
            color: #09f;
        }

        a:hover,
        a:focus,
        a:active 
        {
            color: #344;
        }

    </style>

</head>

    <div id="content">

        <div class="title" align="center">
            <span class="left">
                <img src="images/back.png" onclick="history.go(-1);return false;"/>
            </span>
            <span class="center">
                <img src="images/title.gif"/>
            </span>
            <span class="right">
                <img src="images/home.png" onclick="history.go(-(history.length - 1));"/>
            </span>
        </div>
        <div id="outer">
        </div>

    </div>

为了使用“ insertAdjacentHTML()”,您需要将其定义为一个函数,因为它不是本机JavaScript的一部分。

更好,使用innerHTML()

var d = document.getElementById("mydiv"); d.innerHTML

或者,如果您使用的是jQuery,则可以使用$("#mydiv").html()

就你而言

function changeMe(obj) {
  $(obj).html('<div id="inner"></div>')
  addHeadings();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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