如何添加列表视图上的动态mutilple项目? [英] How to add mutilple dynamic items on listview?

查看:144
本文介绍了如何添加列表视图上的动态mutilple项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个pages.The第一页包含所需的字段,并提交按钮(带校验)的形式。而在第二页列表视图应该在那里。所以,当我在第一页提交按钮点击后,整个领域应该是在名单上显示。
我已经使用本地存储在第二page.It保存数据是perfect.But数据没有在list.And准确显示欲在第一页动态地添加多个项目,从而使它们由我加入多个项目可在第二页中看到。
这里是我的两个页面code。
new.html

I have two pages.The first page contains form with required fields and also a submit button(with validations).And In the second page Listview should be there. So, when i clicked on the Submit button in first page ,the entire fields should be display on the list. I have used local storage for saving the data in the second page.It is perfect.But the data is not displaying exactly on the list.And I want to add multiple items dynamically in the firstpage,So that multiple items which are added by me can be seen in second page. Here are my two pages code. new.html

<!DOCTYPE HTML >
<html >
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<link rel="stylesheet" href="./styles/new.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="./js-css/development-bundle/themes/start/jquery.ui.all.css">
<link rel="stylesheet" media="screen" type="text/css" href="js-css/development-bundle/themes/base/jquery.ui.datepicker.css" />
<script type="text/javascript" src="js-css/development-bundle/jquery-1.10.2.js">    </script>
<script type="text/javascript" src="js-css/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="js-css/development-bundle/ui/jquery.ui.datepicker.js"></script>
 <script type="text/javascript">
  $(function(){
   var pickerOpts = {
  appendText: "",
  defaultDate: "+5",
  showOtherMonths: true,
  dateFormat: "dd/mm/yy",
 };  

  $("#strtd").datepicker({
   minDate: 0
  });

  $("#sub").datepicker({ 
  maxDate: new Date, 
  minDate: new Date(2007, 6, 12)
  });

  $('#strtd').focus(function() {
  this.blur();
  });
  $('#sub').focus(function() {
  this.blur();
  });

  });
  function back() {
 window.open("file:///android_asset/www/index.html");
   }
 //form validation
 function validateForm() {
  localStorage.setItem("RecordName", document.myForm.RecordName.value);
  localStorage.setItem("StartedDate", document.myForm.StartedDate.value);
  localStorage.setItem("SubmitedDate", document.myForm.SubmitedDate.value); 
  var x = document.forms["myForm"]["name"].value;
  var y= document.forms["myForm"]["strtd"].value;
  var z= document.forms["myForm"]["sub"].value;
   if (x==null || x=="") {
    alert("Record name must be filled out");
    return false;
   }
   else if (y==null || y=="") {
    alert("Started Date must be filled out");
    return false;
    }
   else if (z==null || z=="") {
    alert("Submitted Date must be filled out");
    return false;
     }
   else {
   alert("New Record Created");
     }
     }
   </script>
  </head>
    <body>
   <form name="myForm" id="form" type="get" onsubmit="return validateForm()"  action="lead.html">
  <div id="top"> New Record</div>
     <div>
   <h5>Record Name <input type="text" name="RecordName" id="name"></h5>
   </div>
    <div >
    <h5>Started Date <input id="strtd" type="text" name="StartedDate"></h5>
   </div>
    <div>
    <h5>Submitted Date <input id="sub" type="text" name="SubmitedDate"></h5>
   </div><br>
      <div align="center">
    <input  type="submit" id="submit"   value="Submit" >
    </div>
     </form>
    <div align="center">
   <button id="cancel" onclick="back()">Back</button>
     </div>
    </body>
     </html>

和我的第二页lead.html

and my second page lead.html

<!DOCTYPE html>
 <html>
  <head>
  <link rel="stylesheet" href="./styles/lead.css" />
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"> </script>
     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>

     <script>
   function mylead1() 
    {
  window.open("file:///android_asset/www/editlead.html");
     }
   function mylead2() 
    {
   window.open("file:///android_asset/www/editlead.html");
     }
  function mylead3()
    {
  window.open("file:///android_asset/www/editlead.html");
     }
   function onBackKey()
     {
   window.open("file:///android_asset/www/new.html");
      }
   </script>
   </head>
  <body id="lead">
 <div id="top" align="center" > Leads </div>
   <img  id="plus" src="./images/plus.png" onclick="onBackKey()" >
   <div data-role="page"  style="margin-top:100px;" >
   <div data-role="main" id="content" style="min-height:60px;">
   <ul id="unorder" data-role="listview" data-theme="a" data-dividertheme="b">
   <li id="list" data-role="list-divider">
   <label id="label1"  > </label><br>
   <label id="label2"></label><br>
   <label id="label3"></label>
   <img  id="arrow" src="./images/Arrow@2x.png" style="margin-left:250px" onclick="mylead1()">
   </li>  
  </ul>      
   </div>
  </div> 
   </body>
   <script>
  //local storage
      document.getElementById("label1").innerHTML= localStorage.getItem("RecordName"); 
      document.getElementById("label2").innerHTML= localStorage.getItem("StartedDate"); 
     document.getElementById("label3").innerHTML= localStorage.getItem("SubmitedDate"); 
     </script>
   <script>
    $("#submit").click( function() {
   $("ul").append("<li></li>").listview("refresh");
   li.text("#label1");
    $("#unorder").append(li);
    $("#unorder").listview("refresh");
     })
      </script>
    </html>

我的要求是获得所添加的数据(在new.html)第二页(lead.html)上动态
`请指引我解决it.Thanks:)

My requirement is to get the added data(in new.html) dynamically on second page(lead.html) `Please guide me for resolving it.Thanks :)

推荐答案

本地存储空间,做工精细,SO 3 M不关注它。
这里关注的是显示在第二个从第一页的所有数据也以列表形式

local storage is working fine , so m not focusing on it. Here concern is displaying all data from first page in second that too in list format

这是做到这一点的最简单的方法,

this is the most simplest way to do this,

打开第一页
在提交表单假设你正在调用一个函数名的重定向

function redirect()
{
   var form = $("form[name='myForm']");
   form_data = form.serialize();

   window.location = "secondpage.html?"+form_data  // eg: secondpage.html?single=Single2&multiple=Multiple&multiple=Multiple3&radio=radio1
}

打开第二页

功能,将解析的网址,并给参数作为对象

function which will parse url and give parameters as objects

    var re = /([^&=]+)=?([^&]*)/g;
    var decodeRE = /\+/g;  // Regex for replacing addition symbol with a space
    var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );};
    $.parseParams = function(query) {
        var params = {}, e;
        while ( e = re.exec(query) ) { 
            var k = decode( e[1] ), v = decode( e[2] );
            if (k.substring(k.length - 2) === '[]') {
                k = k.substring(0, k.length - 2);
                (params[k] || (params[k] = [])).push(v);
            }
            else params[k] = v;
        }
        return params;
    };



var url = window.location.href ; //'www.example.com?ferko=suska&ee=huu';
    var parameters = $.parseParams( url.split('?')[1] || '' ); // object { ferko: 'suska', ee: 'huu' }

   var li='';
   $.each( parameters, function( key, value ) {
    //    write html code 
   li += "<li>"+value+"</li>"
});

$("ul").html(li);

<ul>
</ul>

这篇关于如何添加列表视图上的动态mutilple项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆