我想將按鈕值從模態傳遞到主窗口上的輸入值。從模態傳遞按鈕值
$('#pickCustomer').click(function() {
var id = $("#customerID").val();
var name = $("#pickCustomer").val();
$("#kodep").val(id);
$("#namap").val(name);
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style="width:32%;min-height:400px;border:1px solid #ccc;border-radius:5px;float:left;padding:1%;">
<table>
<tr>
<td>Customer Name:</td>
<td>
<input id="kodep" name="kodep" type="hidden" value="">
<input style="float:left;width:75%;margin-right:7px;" id="namap" name="namap" type="text" value="">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#customertable">Search</button>
</td>
</tr>
</table>
</div>
<div style="width:80%;left:30%;display:none;" id="customertable" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<table id="tablehasil" class="display" style="width:100%;">
<thead>
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Address</th>
<th>Telp</th>
</tr>
</thead>
<tbody>
<tr>
<td>1001<input id="customerID" type="hidden" value="1001"></td>
<td><button id "pickCustomer" style="background:none;border:none;font-size:13px;" value="test" data-dismiss="modal">testing</button></td>
<td>USA</td>
<td>0000000000</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
當我點擊搜索按鈕,一個模式彈出出現,有訂戶的名單,我用的dataTable JS來排序。
當我點擊按鈕(用戶名)是在模式彈出,輸入名稱不被我想要的值滿了,我沒有看到鉻控制檯
非常感謝關於重複ID的提及。我按照你的建議改變。但仍然如Andrew Halpern回答所述,缺少「pickCustomer」類的等號「 – Gumilar
@Gumilar我沒有注意到這一點。我編輯了我的答案以添加缺少的'='。 – Titus