前臺 html,用的是 springmvc form<form:select id="goodSelectId" path="goodId" items="${goodsList}" itemLabel="name" itemValue="goodCode"> <form:option value="">請選擇商品</form:option></form:select><form:checkbox path="flag" id="flag" value="1" onchange="change(this, 'goodSelectId')"/> javascript 腳本函數: function change(self, targetId) { if ($(self).is(':checked')) { $("#" + targetId).val(""); $("#" + targetId).attr("disabled", true); } else { $("#" + targetId).attr("disabled", false); } } 當下面的 checkbox 打鉤后,要使得 select 元素的值為空我用$("#id").val("");但是發現不起作用傳到后臺“ goodId ”依然有值怎么回事?真正的問題是設值不能傳給form:select里的path(這個關聯java后臺)也就是用select選的可以傳值,但是用這個javascript函數設的值就不能傳給path
如何改變 select 元素的值?
茅侃侃
2018-12-14 15:14:41
