【问题标题】:how to get value from input field and store in local storage and show into table in javascript如何从输入字段中获取值并存储在本地存储中并在javascript中显示到表中
【发布时间】:2017-09-25 13:41:09
【问题描述】:

如何从输入字段中获取值并存储在本地存储中并在 javascript 中显示到表中

<html>
    <head>
        <title></title>
    </head>
    <body>
    <label>Name</label>
    <input type="text">
    <label>Last Name</label>
    <input type="text">
    <table>
    <tr>
        <th>Name</th>
        <th>Last Name</th>
    </tr>

    </table>
    </body>
    </html>

【问题讨论】:

  • 请展示您尝试过的内容。 Stackoverflow 不是免费的代码编写服务或“如何” 教程服务。这里的目标是帮助您修复您的代码。见How to Ask

标签: javascript css html


【解决方案1】:

试试这个,

<html>
    <head>
        <title></title>
    </head>
    <body>
    <label>Name</label>
    <input id="name" type="text">
    <label>Last Name</label>
    <input id="last" type="text">
    <table>
    <tr>
        <th>Name: <label class="name"></label></th>
        <th>Last Name: <label class="last_name"></label></th>
    </tr>

    </table>
    <button id="transfer">Transfer</button>
    </body>
    </html>

使用 Jquery

$(function(){
  $('#transfer').on('click',function(){
   localStorage.setItem('name', $('#name').text());
   localStorage.setItem('last', $('#last').text());
   $('.name').text(localStorage.getItem('name'))
   $('.last_name').text(localStorage.getItem('last'))
 })

});

存储在本地存储中:JQuery setting a local storage variable

在本地存储中获取数据:Getting the value of a variable from localStorage from a different javascript file

希望有帮助:)

【讨论】:

    猜你喜欢
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多