我需要將每個項目的ID添加到onchange
事件的功能中,但<select>
標記不接受表達式。如何將for循環中的每個項目的id傳遞給javascript函數?
一旦用戶從列表中選擇了一個類別,相關項目的id以及值應該被髮送到Ajax以發送到後端。
<c:forEach var="item" items="${Items}">
.....
<s:select id="name"
name="name"
list="@[email protected]"
value="item.category"
onchange='changeItemCategory(${item.id},this.value)'
/>
</c:forEach>
它不接受%{} item.id爲好,當我嘗試item.id它發送請求的功能,但proid變量的值將被「未定義」。
<script>
function changeItemCategory(proid,cat){
alert(proid+cat);
.....
}
</script>
錯誤:
According to TLD or attribute directive in tag file, attribute `onchange` does not accept
any expressions.
什麼是'id'?它是一個int值還是一個字符串 –
id是一個整數。 – AlexCartio1
是不是通過選擇標籤接受的EL表達式?檢查你是否isELIgnored = true –