Home  >  Article  >  Web Front-end  >  JavaScript tips organized_javascript tips

JavaScript tips organized_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:22:341263browse

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

Copy code The code is as follows:
$("[name='checkbox']:even").attr(" checked",'true'); //If this doesn't work, please use prop

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn