Because to do such a job, the two select option is converted to each other, as shown in the following diagram:
This job is to add the click () event to several buttons, which is the general usage:
Copy Code code as follows:
$ ("#but_one"). Click (function () {
$ ("#select1 option:selected"). Appendto ($ ("#select2"));
});
Then I looked up the official document, the description of click Is this, then I still do not have Baidu to answer,
I thought about the reusability of the code and wanted to go directly to the "Select1" and "Select2" strings, and I used the following method:
Copy Code code as follows:
$ ("#but_one"). Click (SELECT ("Select1", "Select2"));
Improve code reusability, based on function changes
function Select (S1,S2) {$ (("#" +s1+ "option:selected")). Appendto ($ ("#" +S2));
}
Later found in jquery, if the use of the function name plus parentheses, is executed, so I bind the event executed, such as SELECT () on the implementation, and then Baidu did not find the answer, went to Google a bit, obediently, and really found, Found the answer on the StackOverflow forum. And then my code becomes this:
Copy Code code as follows:
$ (function () {
var obj1 = {s: "Select1", S2: "Select2"};
var obj2 = {s: "Select2", S2: "Select1"};
$ ("#1"). Click (Obj1,select);
$ ("#2"). Click (OBJ1,SELECT2);
$ ("#3"). Click (Obj2,select);
$ ("#4"). Click (OBJ2,SELECT2);
function Select (event) {
Console.debug (EVENT.DATA.S);
$ ("#" +event.data.s+ "option:selected")). Appendto ($ ("#" +EVENT.DATA.S2));
}
function Select2 (event) {
$ ("#" +event.data.s+ "option"). Appendto ($ ("#" +EVENT.DATA.S2));
}
});
The data in Click (DATA,FN) is actually a JSON object, which can only be fetched by the current event source, and data is placed by default in event, so the data here is EventData, and event.data.name is used when quoting. In other words, all the trigger time methods in jquery require passing parameters to pass arguments through the EventData object:
Here to share the code of the Foreigner:
Copy Code code as follows:
$ ("Select#test"). Change ({msg: "OK"}, function (event) {
MyHandler (EVENT.DATA.MSG);
});