select2下拉框的使用
<tr>
<td>
<select id="simHatyubusyo" th:field="*{simHatyubusyo}" class="select2" disabled>
<option th:each="c:*{hachusakiTantobushoList}"
th:value="${c.id}" th:text="${c.text}"></option>
</select>
</td>
</tr>
<tr>
<td>
<select id="simHatyubusyo2" th:field="*{simHatyubusyo2}" class="select2" disabled>
<option th:each="c:*{hachusakiTantobushoList}"
th:value="${c.id}" th:text="${c.text}"></option>
</select>
</td>
</tr>
<tr>
<td>
<select id="simHatyubusyo3" th:field="*{simHatyubusyo3}" class="select2" disabled>
<option th:each="c:*{hachusakiTantobushoList}"
th:value="${c.id}" th:text="${c.text}"></option>
</select>
</td>
</tr>
<tr>
<td>
<select id="simHatyubusyo4" th:field="*{simHatyubusyo4}" class="select2" disabled>
<option th:each="c:*{hachusakiTantobushoList}"
th:value="${c.id}" th:text="${c.text}"></option>
</select>
</td>
</tr>
$("#simHatyubusyo,#simHatyubusyo2,#simHatyubusyo3,#simHatyubusyo4").each(function(item) {
var sdataList = [
{id: 1, text:'OPS-COFFEE-1'},
{id: 2, text:'OPS-COFFEE-2'},
{id: 3, text:'OPS-COFFEE-3'}
]
$(this).empty();
$(this).select2({
data: sdataList
});
$(this).removeAttr("disabled");
let word = $(this).select2('data')[0].text;
$(`select2对象`).val(需要被选中的id).select2();
});
$('select2对象').select2({
minimumResultsForSearch: -1
});
for (var i = 0; i < jtv010NyusatsukaishaFormCount; i++) {
sinEdano = singleData.jtv010NyusatsukaishaFormList[i].sinEdano - 1;
sinNyusyacd = singleData.jtv010NyusatsukaishaFormList[i].sinNyusyacd.toString();
$(`#sinNyusyacd${sinEdano}`).select2({
data: eval(`singleData.nyusatsuKaishaList${sinEdano + 1}`),
});
$(`#sinNyusyacd${sinEdano}`).val(sinNyusyacd).select2();
}
eval函数的使用
for (var i = 0; i < gijyutsuTableCount; i++) {
eval(`submitData.jtaTanSyu${i + 1} =
$('#jtaTanSyu${i + 1}').prop('checked') ? 1 : 0`);
if ($(`#jtaTanSyu${i + 1}`).prop('checked')) {
jtaTanSyacd = $(`#jtaTanSyacd${i + 1}`).val();
}
}
checkbox设置单选
<table id="gijyutsuTable" class="border_table">
<tr>
<td style="width: 50px;">
<input id="jtaTanSyu1" th:checked="*{jtaTanSyu1} eq '1'" type='checkbox' />
</td>
</tr>
<tr>
<td style="width: 50px;">
<input id="jtaTanSyu2" th:checked="*{jtaTanSyu2} eq '1'" type='checkbox' />
</td>
</tr>
<tr>
<td style="width: 50px;">
<input id="jtaTanSyu3" th:checked="*{jtaTanSyu3} eq '1'" type='checkbox' />
</td>
</tr>
</table>
$("#gijyutsuTable input:checkbox").on("click", function(obj) {
$("#gijyutsuTable input:checkbox").each(function(index, chekboxItem) {
$(chekboxItem).prop('checked', false);
});
$(obj.target).prop('checked', true);
});