開發中遇到這樣一個問題:
input :radio ,checkbox ,點選後 觸發事件,執行事件中的邏輯。
而 實際中 有這樣一個需求:點選某一個控件(樹形菜單節點) 自動 觸發 radio/checkbox,或者 反綁定時 将radio/checkbox 綁定的事件 效果 實作。
正常做法是:
$("input[name='" + item.IndexId + "'][value=" + item.IndexVal + "]").attr("checked", true); //勾選
layui.form.render();// 必須要重新重新整理
以上隻是 給控件指派,但是其事件未執行,隻能用jquery 單獨處理。
還有一種更簡單的做法,直接激活 觸發事件:
//直接觸發其點選事件,計算得分
$("input[name='" + item.IndexId + "'][value=" + item.IndexValue + "]").next().click();