More elegant jQuery stitching drop-down box

Source: Internet
Author: User

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!

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.