首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我用html做了一个表单,需要添加序列号,它在提交表单时会增加,如发票栏中的代码所示。

我用html做了一个表单,需要添加序列号,它在提交表单时会增加,如发票栏中的代码所示。
EN

Stack Overflow用户
提问于 2016-10-05 13:59:42
回答 1查看 488关注 0票数 0

我用html做了一个表单,需要添加序列号,在提交表单时,序列号会增加,如发票栏中的代码所示。

代码语言:javascript
复制
<html>
  <head>
    <meta charset="utf-8">
    <title>Invoice</title>
    <link rel="stylesheet" href="style.css">
    <link rel="license" href="http://www.opensource.org/licenses/mit-license/">
    <script src="script.js"></script>
  </head>
  <body>
    <header>
    <h1>Invoice</h1>
    <address contenteditable>
      <p>Jonathan Neal</p>
      <p>101 E. Chapman Ave<br>Orange, CA 92866</p>
      <p>(800) 555-1234</p>
   </address>
   <span>
     <img alt="" src="logo.png">
     <input type="file" accept="image/*">
   </span>
 </header>
 <article>
   <h1>Recipient</h1>
   <address contenteditable>
     <p>Some Company<br>c/o Some Guy</p>
   </address>
   <table class="meta">
  ***<tr>enter code here
     <th><span contenteditable>Invoice #</span></th>
     <td><span contenteditable>101138</span></td>
     </tr>***
     <tr>
     <th><span contenteditable>Date</span></th>
     <td><span contenteditable>January 1, 2012</span></td>
     </tr>
     <tr>
     <th><span contenteditable>Amount Due</span></th>
     <td><span id="prefix" contenteditable>$</span>
     <span>600.00</span>
     </td>
     </tr>
    </table>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-16 14:09:48

然后可以使用Javascript;首先,向元素中添加一个id,这样您就可以访问它:

代码语言:javascript
复制
 <tr>
   <th><span contenteditable>Invoice #</span></th>
   <td><span contenteditable id="invoce">101138</span></td>
 </tr>

然后,可以将以下js添加到脚本文件中:

代码语言:javascript
复制
var invoice = 101138;
$('button').on('click', function () {
    invoice++; // increments invoice
    $('#invoice').text(invoice); // updates text on screen
});

也就是说,如果使用jquery,而'button'是按钮的选择器。

但是,这将在用户离开站点时重置。如果您希望它是持久的,您需要使用像cookie或本地存储之类的东西。

为了使其持久,您可以使用多种方法,例如本地存储api

这里就是一个完整的例子。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39876049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档