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.