JavaScript tips for finishing _javascript skills

Source: Internet
Author: User

This article summarizes the small techniques of JavaScript. Share to everyone for your reference, specific as follows:

1. Organize default events

To block the default event, h5 the default input type= ' date ' has no effect on some browsers and Android devices, when you want to invoke the h5+ time selector, but to organize the default click event for input, the code is as follows:

Select Time
$ ("#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 ("Date not selected:" +e.message);
  },{ Title: "Please select Expiration Time", Mindate:new Date ()}); 


2. Determine if the input type= ' checkbox ' is selected, the code is as follows

if (!$ ("#shopregister #checkaggree"). Is (": Checked")) {
  alert ("Please agree to the registration agreement");
  return false;
}

3. Get the value of the one selected in multiple checkbox, 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 selection

Copy Code code as follows:
$ ("[name= ' checkbox ']:even"). attr ("Checked", ' true '); If this stuff doesn't work, please use Prop.

5. Get the value of the title property in more than one picture

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.ajax Show progress picture during 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) {//server
   side successful
  }
  else
   {//Server side Failure
  }
}). Fail (function () {
  // Ajax request failed
});

I hope this article will help you with JavaScript programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.