,以便應用遮罩輸入字段爲自動格式值與模板你將需要聽取輸入按鍵事件並根據您的面具進行處理。有一些腳本已經這樣做,如Masked Input Plugin for jQuery。
如果您希望輸入文本僅具有$0.00
作爲初始值,那麼執行起來相當容易。 你可以像這樣通過JavaScript創建並插入一行到表:
<html>
<body>
<button id="insertRowButton">Insert</button>
<table>
<thead>
<tr><th>Text</th><th>Input</th></tr>
</thead>
<tbody id="tableBody">
</tbody>
</table>
<script>
(function() {
// Elements used
var tableBody = document.getElementById('tableBody'),
insertRowButton = document.getElementById('insertRowButton');
// Create a new row template
function createRow() {
var tr = document.createElement('tr'),
tdText = document.createElement('td'),
tdInput = document.createElement('td'),
sub = document.createElement('sub'),
input = document.createElement('input'),
text = document.createTextNode('This is a text node '),
subscriptText = document.createTextNode('with subscript');
sub.appendChild(subscriptText);
tdText.appendChild(text);
tdText.appendChild(sub);
input.value = '$0.00';
tdInput.appendChild(input);
tr.appendChild(tdText);
tr.appendChild(tdInput);
return tr;
}
// Insert a new row into table
function insertRow() {
var tr = createRow();
tableBody.appendChild(tr);
}
// Bind events
insertRowButton.addEventListener('click', insertRow);
}());
</script>
</body>
</html>
這是它在的jsfiddle:http://jsfiddle.net/ck7qargw/
請張貼你的代碼。 – j08691 2014-11-14 15:13:54
@ j08691對不起,已更新 – sudobangbang 2014-11-14 15:23:24