亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何定位具有使用 Thymeleaf 組成的 id 的輸入字段的值

如何定位具有使用 Thymeleaf 組成的 id 的輸入字段的值

喵喵時光機 2023-06-08 14:39:40
單擊按鈕我想獲取輸入字段的值。但是,我無法定位輸入字段,因為字段 id 是另一個組合值。我試過this.value這似乎只傳遞了 req.id 而不是輸入字段中輸入的值。我知道獲取輸入字段值的正確方法是: $(selector).val()但是,以下不適用于當前的實現。 $(incidentNumber+${req.id}).val()<tr th:each="req : ${requests}">        <td><input th:id="incidentNumber+${req.id}" th:name="incidentNumber+${req.id}"                       style="width:100%" type="text" th:value="${req.incidentNumber}"><button th:value="${req.id}"class="button" type="button" onclick="validate_ticket_number(this.value)">Update</button></a></td></tr>我希望輸出是在“incidentNumber+${req.id}”輸入字段中輸入的值
查看完整描述

1 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

連接字符串的正確方法是:

th:id="'incidentNumber'+${req.id}"

當您在 Javascript 中訪問它時(jQuery通過元素的 Id 選擇器)您不能使用表達式thyemeleaf,它必須是:

$('#incidentNumber100').val() // req id 100 is just an example

如果要使其動態化,請將元素的 Id 傳遞給目標函數,并在函數中使用 Id 檢索值。

<button th:value="${req.id}"class="button" type="button"th:onclick="'validate_ticket_number(\'incidentNumber'+${req.id}+'\')'"> Update</button>

然后在validate_ticket_number()函數中使用提供的 id 訪問值,例如:

function validate_ticket_number(id){ 
 var value = $(id).val();
}


查看完整回答
反對 回復 2023-06-08
  • 1 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號