我用html做了一个表单,需要添加序列号,在提交表单时,序列号会增加,如发票栏中的代码所示。
<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>发布于 2016-10-16 14:09:48
然后可以使用Javascript;首先,向元素中添加一个id,这样您就可以访问它:
<tr>
<th><span contenteditable>Invoice #</span></th>
<td><span contenteditable id="invoce">101138</span></td>
</tr>然后,可以将以下js添加到脚本文件中:
var invoice = 101138;
$('button').on('click', function () {
invoice++; // increments invoice
$('#invoice').text(invoice); // updates text on screen
});也就是说,如果使用jquery,而'button'是按钮的选择器。
但是,这将在用户离开站点时重置。如果您希望它是持久的,您需要使用像cookie或本地存储之类的东西。
为了使其持久,您可以使用多种方法,例如本地存储api。
这里就是一个完整的例子。
https://stackoverflow.com/questions/39876049
复制相似问题