jquery foreach用法舉例
阿新 • • 發佈:2019-02-20
分享下jquery中的foreach的用法。
例如:
jquery程式碼,有關foreach的用法。
例如:
<form id="input_iForm" action="${pageContext.request.contextPath}/transfer/input_salary.shtml"> <input type="text" class="input_w150" vili="true" onkeyup="formatBankNo(this)"/> <input type="text" class="input_w150" vili="true" onkeyup="formatBankNo(this)"/> <input type="text" class="input_w150" vili="true" onkeyup="formatBankNo(this)"/> </form> www.jbxue.com $("input").each(function(index){ //取得整個頁面的input值 $("input:text").each(function(index){ alert(index);//迴圈的下標值,從0開始 alert(this.value); alert($(this).attr("type")); //自帶屬性可以用this(Dom)直接取值 alert($(this).attr("vili")); //自定義屬性需要用attr(Jquery)取值 //if($(this).attr("vili")=="true"&&){ //} });
jquery程式碼,有關foreach的用法。
$.ajax({ url: '<%=basePath%>schedule/getMonthRecordLs.action', dataType: 'json', success: function(data) { var events = []; $(data).each(function(i,val) { events.push({ id: val.sc_id, title: val.sc_planemp, start: new Date(val.sc_date), color: val.sc_classes=='1'?'':'#993300' }); }); callback(events); } });