如何在Html中存储多个数据 [英] How Do I Store Multiple Data In Html

查看:67
本文介绍了如何在Html中存储多个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下,通过文本框,我们可以添加/存储单个值。如果我想在html中存储多个值/数据,那么我必须做什么。

任何帮助将不胜感激

解决方案

你提到'商店',如果你真的是指在客户端存储价值,那么读出< a href =http://www.codeproject.com/Articles/768002/Beginners-Guide-to-HTML-CSS-Web-Storage-Wizardry> HTML5初学者指南& CSS3 - Web存储向导 [ ^ ]

否则,如果您想在客户端动态创建多个文本框,请使用javascript,例如

< pre lang =xml> < !DOCTYPE html >
< html >
< ; 正文 >

< id = myTable style = border:1px solid black >
< tr >
< td > Row1 cell1 < / td >
< td > Row1 cell2 < / td >
< / tr >
< tr >
< td > Row2 cell1 < / td >
< td > Row2 cell2 < / td >
< / tr >
< / table >
< br >

< 按钮 onclick = addTextbox() > 添加文本框< / button >

< script >
function addTextbox(){
var table = document .getElementById( myTable的);
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML =< input type =' text' > ;
cell2.innerHTML =NEW CELL2;
}
< / script >

< / body >
< / html < span class =code-keyword>>


您可以通过多种方式执行此操作。



您可以将它们存储在javascript中。



例如json:



var textAndOtherValues {text:someText,otherValue:somethingdifferent};



当你需要访问你的值时你可以做



MyTextbox.value = textAndOtherValues ['text'];

console.log(textAndOtherValues ['otherValue'];



或者你可以使用隐藏值:



Html:









问候希望这就是你想要的......


I want to ask that through textbox, we can add/store a single value. If I want to store multiple value/data in html then what I have to do.
any help would be appreciated

解决方案

You mention 'store', if you really mean storing value on client side, then read out Beginner's Guide to HTML5 & CSS3 - Web Storage Wizardry[^]
Otherwise, if you mean to create multiple text boxes dynamically on the client side, use javascript, e.g.

<!DOCTYPE html>
<html>
<body>

<table id="myTable" style="border: 1px solid black">
  <tr>
    <td>Row1 cell1</td>
    <td>Row1 cell2</td>
  </tr>
  <tr>
    <td>Row2 cell1</td>
    <td>Row2 cell2</td>
  </tr>
</table>
<br>

<button onclick="addTextbox()">Add Text Box</button>

<script>
function addTextbox() {
    var table = document.getElementById("myTable");
    var row = table.insertRow(0);
    var cell1 = row.insertCell(0);
    var cell2 = row.insertCell(1);
    cell1.innerHTML = "<input type='text'>";
    cell2.innerHTML = "NEW CELL2";
}
</script>

</body>
</html>


You can do this in multiple ways.

You can store them in javascript.

For example json:

var textAndOtherValues { "text" : "someText", "otherValue" : "somethingdifferent" };

When you need to acces your values you can do

MyTextbox.value = textAndOtherValues['text'];
console.log( textAndOtherValues['otherValue'];

or you can use hidden values:

Html:




greetings hope this is what you want...


这篇关于如何在Html中存储多个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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