Home > Article > Web Front-end > JavaScript tips organized_javascript tips
This article summarizes JavaScript tips. Share it with everyone for your reference, the details are as follows:
1. Organize default events
Prevent the default event. The default input type='date' of h5 has no effect on some browsers and android devices. In this case, the time selector of h5+ must be called, but the default click event of the input must be organized. The code is as follows:
//选择时间 $("#end_time").on("click",function(event){ event.preventDefault(); plus.nativeUI.pickDate( function(e){ var d = e.date; // console.log(d.Format('yyyy-MM-dd')); $("#end_time").val(d.Format('yyyy-MM-dd')); },function(e){ console.log( "未选择日期:"+e.message ); },{title:"请选择到期时间",minDate:new Date()}); });
2. Determine whether input type='checkbox' is selected, the code is as follows
if (!$("#shopregister #checkaggree").is(":checked")) { alert("请同意注册协议"); return false; }
3. Get the value of the selected one among multiple checkboxes, the code is as follows
<input name='is_refund' id='refund_1' type='radio' value='1' /> <input name='is_refund' id='refund_0' checked='checked' type='radio' value='0' /> $("#shopregister input[name='is_refund']:checked").val();
4.Set checkbox selected
5. Get the value of the title attribute in multiple pictures
user.id_pic1 = $($("#shopregister .id_pic")[0]).attr("title"); user.id_pic2 = $($("#shopregister .id_pic")[1]).attr("title"); user.id_pic3 = $($("#shopregister .id_pic")[2]).attr("title");
6. Display progress pictures during ajax submission
$.ajax({ type: 'POST', url: configManager.RequstUrl + "/api/user/createstore", data: postdata, beforeSend:function(){ $("#waitingupload").removeClass("heisebghid").addClass("heisebg");} }).done(function (data) { $("#waitingupload").removeClass("heisebg").addClass("heisebghid"); if ("success" == data.state) { //服务端成功 } else { //服务端失败 } }).fail(function () { //ajax请求失败 });
I hope this article will be helpful to everyone in JavaScript programming.