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.