JavaScript tips _ javascript tips-js tutorials

Source: Internet
Author: User
This article mainly introduces the JavaScript tips and summarizes the six common practical skills used by JavaScript. It is a summary of the JavaScript corner skills. For more information, see this article. We will share this with you for your reference. The details are as follows:

1. Organize default events

Stop default events. h5's default input type = 'date' has no effect on Some browsers and android devices. In this case, call the h5 + time selector, however, to organize the default click Event of input, the Code is as follows:

// Select the 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. Check whether 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. Obtain the selected value in multiple checkboxes. The Code is as follows:

$("#shopregister input[name='is_refund']:checked").val();

4. Set checkbox Selection

The Code is as follows:

$ ("[Name = 'checkbox']: even"). attr ("checked", 'true'); // If the goods do not work, use prop

5. Obtain the title attribute values of multiple images.

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) {// server succeeded} else {// server Failed }}). fail (function () {// ajax request failed });

I hope this article will help you design JavaScript programs.

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.