Browse to a question in stack overflow: How to use jquery to better splice the dropdown box code? This small demand has also been written many times in practice, but users provide a more elegant way to pull down the jquery mosaic box.
The code is as follows:
var options = $ ("#options");
$.each (result, function () {
Options.append ($ ("<option/>"). Val (this. Imagefolderid). Text (this. Name));
});
And then turn out what you wrote a short time ago (第8-11 line):
To change the template drop-down box
function Changetempalte (scene_id) {
$.post ("/tipsadmin/getalltemplate", {scene_id:scene_id}, function (data) {
if (Data.length = = 0) {
templateform[' bubble '] ();
return false;
}
option = ';
$.each (data, function (ID, item) {
Option + = ' <option value= ' + item.id + ' > ' + item.name + ' </option> ';
});
$ ("#template_id"). HTML (option);
Show the first template by default
Previewtemplate (data[0].id);
}, ' json ');
}
With the stitching string of the wording, contrast, the code is obviously not elegant!