jquery Add options Click event and pass Value

Source: Internet
Author: User

Description: According to choose different store option, send different ID value, show different product list

var formstr = "{' SupplierId ': ' Supply Chain Enterprise |%-jm-sprt-%|93794498-3 '}";

$.ajax ({
Type: "Post",
DataType: "JSON",
Cache:false,
URL: ".. /.. /.. /webservice/gmall.json ",//submit to general handler request data
Data: "Businesscode=61001001&message=" +encodeuri (FORMSTR). Replace (/\+/g, "%2b"),
Async:false,
Error:function () {
Alert ("Connection error!!!");
Layer.alert ("Data loading failed, please contact the Administrator!") ", 0);
},
Success:function (data) {
var Datajson = Strtojson (data.msg);
var shopname = dataJson.body.gmPage;

if (datajson.head.status== ' 000000 ') {
$.each (Shopname,function (I,item) {
$ ("#store"). Append ("<option id=" "+item.id+" ' value= ' "+item.shoptype+" ' title= ' "+item.name+" > "+item.name+" </option> ");
})


$ ("select"). On (' click ', Function () {
var opt = $ (this). Children (' option:selected ');
var shopid = $ (opt). attr (' id ');
var Shoptype = $ (opt). Val ();
var formstrshop = "{' Shopid ':" +shopid+ ", ' Shoptype ':" +shoptype+ "}";
if ($ ("option"). val () = = ") {
$ ("#tb"). empty ();
}
$.ajax ({
Type: "Post",
DataType: "JSON",
Cache:false,
URL: ".. /.. /.. /webservice/gmall.json ",//submit to general handler request data
Data: "Businesscode=61001003&message=" +encodeuri (formstrshop). Replace (/\+/g, "%2b"),
Async:false,
Error:function () {
Layer.alert ("Data loading failed, please contact the Administrator!") ", 0);
},
Success:function (data) {
var Datajson = Strtojson (data.msg);
var shopname = dataJson.body.gmPage;
if (datajson.head.status== ' 000000 ') {
$.each (Shopname,function (I,item) {
var attributeValue11 = Datajson.body.gmpage[i].attributevalue11;
$ ("#tb"). empty ();
$ ("#tb"). Append ("<tr id= '" +item.id+ ">"
+ "<td><input type= ' checkbox ' value= '" +item.id+ "' name= ' price '/></td> '
+ "<td>" +item.sn+ "</td>"
+ "<td>" +item.name+ "</td>"
+ "<td>" +item.attributevalue11+ "</td>"
+ "<td><input type= ' text ' name= ' discount ' class= ' text ' style= ' width:100px '/></td> '
+ "<td>" +0+ "</td></tr>"
);
})
}
}
});
})
}
}
});

"Simple Example" <select name= "" Id= "" >
<option value= "1" id= "1" >123</option>
<option value= "2" id= "2" >gfg</option>
<option value= "3" id= "3" >ds3</option>
<option value= "4" id= "4" >1fgtr3</option>
<option value= "5" id= "5" >6y3</option>
<option value= "6" id= "6" >1fbnh3</option>
<option value= "7" id= "7" >1vdf3</option>
</select>
<script src= "Jquery-1.8.2.min.js" ></script>
<script>
$ (function () {
$ (' select '). On (' click ', Function () {
$ (this). On (' click ', function () {This step can be omitted without the option of a click event
var $opt = $ (this). Children (' option:selected ');
Console.log ($ ($opt). attr (' ID '), $ ($opt). Val (), $ ($opt). html ());
// })
})
})
</script>

jquery Add options Click event and pass Value

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.