如何使輸入字段代替逗號分隔的文本與波紋管表格匹配。如何在單擊表格單元格時輸入字段
在我婁代碼時,單擊表格單元格將其添加自己的文本字符串轉換爲輸入字段像A1,A2,A3,A4
但我想從表單元格的將輸出的每個字段輸入字段和字段的值點擊。其實我想保存每個字段值到數據庫。這就是爲什麼我需要輸入字段。
<input type="text" class="some_class" value="text of the the cell" >
有人可以幫我修改我的代碼嗎?
我的表像
$(function() {
var isMouseDown = false,
isHighlighted;
$("#ticketLayout .select")
.mousedown(function() {
isMouseDown = true;
$(this).toggleClass("highlighted");
ticketName();
\t calculate();
isHighlighted = $(this).hasClass("highlighted");
return false; // prevent text selection
})
.mouseover(function() {
if (isMouseDown) {
$(this).toggleClass("highlighted", isHighlighted);
ticketName();
\t \t calculate();
}
});
$(document)
.mouseup(function() {
isMouseDown = false;
});
});
function ticketName(){
var count = $("#ticketLayout td.highlighted").length;
$(".ticket-count").text(count);
var ticketValue = "";
$("#ticketLayout td.highlighted").each(function(){
ticketValue += $(this).text() + ",";
});
$(".selected-ticket").val(ticketValue);
}
//Calculate Price
function calculate()
{
\t var qty = document.getElementById("ticket-count").innerText;
\t var value = document.getElementById("item-price").innerText;
\t var result = value * qty;
\t
\t $(".total-price").val(result);
}
table .select {
width:40px;
height:40px;
text-align:center;
vertical-align:middle;
background-color:#fff;
border:1px solid #c0c0c0;
}
table .selected {
width:40px;
height:40px;
text-align:center;
vertical-align:middle;
background-color:red;
border:1px solid #c0c0c0;
}
table td.highlighted {
background-color:#60fc60;
}
.ticket-panel{
margin-top:30px;
margin-left:30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="ticket-panel">
<p>Ticket Fare: <span id="item-price" class="item-price">450</span>Taka</p>
\t \t \t \t \t \t <table cellpadding="0" cellspacing="0" id="ticketLayout">
\t \t \t \t \t \t \t <tbody>
\t \t \t \t \t \t \t <tr><td class="select">A1</td><td class="select">A2</td><td></td><td class="select">A3</td><td class="select">A4</td></tr>
\t \t \t \t \t \t \t <tr> <td class="select">B1</td><td class="selected">B2</td><td></td><td class="select">B3</td><td class="select">B4</td></tr>
\t \t \t \t \t \t \t
</tbody>
</table>
\t \t \t \t \t <form action="booking.php" method="post">
\t \t \t \t \t \t <div class="ticket-data">
<div class="seats-container"></div>
\t \t \t \t \t \t \t \t <p>Your Seat:<input id="tickets" name="ticket_no" type="text" class="selected-ticket" /></p>
\t \t \t \t \t \t \t \t <p>Seat No: <span class="ticket-count" id="ticket-count" > </span></p>
\t \t \t \t \t \t \t \t <p>Total Price: <input type="number" name="total-price" id="total-price" class="total-price" /></p>
\t \t \t \t \t \t \t \t <button id="submit" type="submit" name="submit" class="btn btn-success">Continue</button>
\t \t \t \t \t \t \t </div>
\t \t \t \t \t </form>
可能會在每個表格之前添加輸入字段並在點擊時隱藏/顯示它們? – jarasss
不,它應該添加到我的波紋管窗體,其中輸出顯示 – Firefog
document.createElement()或$('')並追加新你有節點嗎? – Shilly