[英]Grab Data on the Fly from Table HTML
這可能有點難以解釋,但我正在顯示一個 2 x 2 的網格。當您單擊單元格的文本(例如 0,1)時,它會彈出一個彈出框並將這些坐標存儲在隱藏的價值觀。 然后這些隱藏的值將通過 POST 提交到表單。
這是我編寫的一些示例代碼,希望能闡明我正在嘗試做的事情: https : //jsfiddle.net/v08bzm9k/1/
<table border=1>
<tr>
<td class='grid-cells'><a href='#myPopup' data-rel='popup'>1</a></td>
<td class='grid-cells'><a href='#myPopup' data-rel='popup'>2</a></td>
</tr>
<tr>
<td class='grid-cells'><a href='#myPopup' data-rel='popup'>3</a></td>
<td class='grid-cells'><a href='#myPopup' data-rel='popup'>4</a></td>
</tr>
</table>
<div data-role="popup" id="myPopup" class="ui-content" style="min-width:250px;">
<form method="post" action="save-square.php">
<div>
<h3>Pick This Square:</h3>
<label for="name" class="ui-hidden-accessible">Name:</label>
<input type="text" name="name" id="name" placeholder="Name">
<label for="email" class="ui-hidden-accessible">Email:</label>
<input type="text" name="email" id="email" placeholder="Email">
<input type="submit" data-inline="true" value="Submit">
<div id='row'></div>
<div id='col'></div>
</div>
</form>
</div>
我會通過 JavaScript 將我單擊的單元格的值存儲到隱藏字段中嗎?
我更新了https://jsfiddle.net/v08bzm9k/2/
是的,您可以使用隱藏字段。 在您的表單中添加:
<input type="hidden" name="coords" id="coords" value="">
將此JS添加到您的頁面:
function setCoords(newCoords) {
$('#coords').val(newCoords);
}
在您的鏈接中,添加一個 onClick:
<a href='#myPopup' data-rel='popup' onclick="setCoords('1,1');">1</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.