如何更新和保存使用Xml填充的表行 [英] how to update and save a table row populated using Xml

查看:87
本文介绍了如何更新和保存使用Xml填充的表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Html代码中(我使用XML文件填充html表),有一个动态选择选项,它根据Xml文件中的产品名称填充。如果我从中选择任何选项,它将显示包含该产品的表格。



现在我想编辑我桌子上的数据,所以我添加了makeEditale on dbclick on td,使日期在dubleclick上可编辑。但是如何在按下保存按钮后将其保存到我的xml(每行都有)。



谢谢你<请帮助



这是我的代码。 html



In my Html code(I am populating a html table with an XML file), there is a dynamic select option which is populated on the basis of product name from Xml file. and if I choose any option from it it will show the table consisting that product.

Now I want to edit the data on my table, So I have added makeEditale on dbclick on td, which make the date editable on dubleclick. But how to save it to my xml after pressing save buton(which is on every row).

Thank you< please help

Here is my code. html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

</head>
<body>
    </br>
    Select an option:
    <select type="input" name="ProductName" id="ProductList"  onchange="searchXML()">
        <option></option>
        <option>all</option>
    </select>
    </br>

    <div id="results">
    </div>

<script type="text/javascript">
var attribute="";
var sel;
var productoptions="";
var arrayout=[];
sel=document.getElementById('ProductList');
document.onpageshow=dropdown();
function dropdown()
{

    if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    xmlhttp.open("GET","xml/test.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;

    attribute=xmlDoc.getElementsByTagName("ProductName");


    for (i=0;i<attribute.length;i++)

    {

    var opt=document.createElement('option');

    productoptions=xmlDoc.getElementsByTagName("ProductName")[i].childNodes[0].nodeValue;

    opt.innerHTML = productoptions;

    opt.value=productoptions;

        for (j=0;j<i;j++)

        {

            arrayout[j]=opt.value;

            if(opt.value!=arrayout)

            {

            sel.appendChild(opt);

            }



        }

    }

    arrayout="";

}





var product=[];

var quantity=[];

var date=[];

var grossprice=[];

var profit=[];

var divText=[];



function searchXML()

{



    if (window.XMLHttpRequest)

        {// code for IE7+, Firefox, Chrome, Opera, Safari

        xmlhttp=new XMLHttpRequest();

        }

        else

        {// code for IE6, IE5

        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

        }

    xmlhttp.open("GET","xml/test.xml",false);

    xmlhttp.send();

    xmlDoc=xmlhttp.responseXML;



    x=xmlDoc.getElementsByTagName("ProductName");

          input = document.getElementById("ProductList").value;

          size = input.length;

          divText=""

          if (input == "")

          {

              document.getElementById("results").innerHTML= "Please select a Product Name!";

              return false;

          }

          if (input === "all")

          {

                var y=xmlDoc.getElementsByTagName("entry");

                    for (i=0;i<y.length;i++)

                    {

                          date=xmlDoc.getElementsByTagName("Date")[i].childNodes[0].nodeValue;

                          product=xmlDoc.getElementsByTagName("ProductName")[i].childNodes[0].nodeValue;

                          quantity=xmlDoc.getElementsByTagName("Quantity")[i].childNodes[0].nodeValue;

                          grossprice=xmlDoc.getElementsByTagName("GrossPrice")[i].childNodes[0].nodeValue;

                          profit=xmlDoc.getElementsByTagName("Profit")[i].childNodes[0].nodeValue;

                          if (divText==="")

                          {

                            divText="<h2>The product details are:</h2><br /><table class=tablesorter >";

                            divText+="<thead><tr><th>Date</th><th>Product</th><th>Quantity</th><th>GrossPrice</th><th>Profit</th><th>Action</th></tr></thead><tbody>";

                          }

                          divText += "<tr><td class=edit>" + date + "</td><td class=edit>" + product + "</td><td class=edit>" + quantity + "</td><td class=edit>" + grossprice + "</td><td class=edit>" + profit + "</td><td>" + "<input type=button value=save> "  +  "</td></tr>";
          }
         }

          for (i=0;i<x.length;i++)

          {

              startString = x[i].childNodes[0].nodeValue;

              if (startString.toLowerCase() == input.toLowerCase())

              {

                  date=xmlDoc.getElementsByTagName("Date")[i].childNodes[0].nodeValue;

                  product=xmlDoc.getElementsByTagName("ProductName")[i].childNodes[0].nodeValue;

                  quantity=xmlDoc.getElementsByTagName("Quantity")[i].childNodes[0].nodeValue;

                  grossprice=xmlDoc.getElementsByTagName("GrossPrice")[i].childNodes[0].nodeValue;

                  profit=xmlDoc.getElementsByTagName("Profit")[i].childNodes[0].nodeValue;

                  if (divText==="")

                          {

                            divText="<h2>The product details are:</h2><br /><table class=tablesorter >";

                            divText+="<thead><tr><th>Date</th><th>Product</th><th>Quantity</th><th>GrossPrice</th><th>Profit</th><th>Action</th></tr></thead><tbody>";

                          }

                          divText += "<tr><td class=edit>" + date + "</td><td class=edit>" + product + "</td><td class=edit>" + quantity + "</td><td class=edit>" + grossprice + "</td><td class=edit>" + profit + "</td><td>" + "<input type=button value=save> "  +  "</td></tr>";

              }
          }
          if (divText=="")
          {
              divText = "<h2>The product does not exist.</h2>";
          }
          else
          {
              divText+="</tbody></table> <p> double click on the item to edit</p>";
          }
          document.getElementById("results").innerHTML= divText;

}

$(document).on(&quot;dblclick&quot;, &quot;td.edit&quot;, function(){ makeEd<pre><pre lang="HTML"><small><big><pre><pre lang="text"><pre lang="text"></pre></pre></pre></big></small></pre></pre>itable(this); });

function makeEditable(element) {
    $(element).html('<input id="editbox" size="'+  $(element).text().length +'" type="text" value="'+ $(element).text() +'">');
    $('#editbox').focus();
}


</script>

</body>
</html>







My Xml file






My Xml file

<?xml version="1.0" encoding="UTF-8"?>
<item>
      <entry>
        <ProductName>milk</ProductName>
        <Date>2/10/2007</Date>
        <Quantity>20</Quantity>
        <GrossPrice>100</GrossPrice>
        <Profit>20</Profit>
      </entry>
      <entry>
        <ProductName>sugar</ProductName>
        <Date>2/09/2009</Date>
        <Quantity>45</Quantity>
        <GrossPrice>1000</GrossPrice>
        <Profit>100</Profit>
      </entry>
      <entry>
        <ProductName>sugar</ProductName>
        <Date>2/09/2010</Date>
        <Quantity>40</Quantity>
        <GrossPrice>600</GrossPrice>
        <Profit>50</Profit>
      </entry>
</item>

推荐答案

(document).on(&quot;dblclick&quot;, &quot;td.edit&quot;, function(){ makeEd<pre><pre lang=\"HTML\"><small><big><pre><pre lang=\"text\"><pre lang=\"text\"></pre></pre></pre></big></small></pre></pre>itable(this); });

function makeEditable(element) {
(document).on(&quot;dblclick&quot;, &quot;td.edit&quot;, function(){ makeEd<pre><pre lang="HTML"><small><big><pre><pre lang="text"><pre lang="text"></pre></pre></pre></big></small></pre></pre>itable(this); }); function makeEditable(element) {


(element).html('<input id=\"editbox\" size=\"'+
(element).html('<input id="editbox" size="'+


(element).text().length +'\" type=\"text\" value=\"'+
(element).text().length +'" type="text" value="'+


这篇关于如何更新和保存使用Xml填充的表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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