简体   繁体   中英

Am I able to add an img tag inside the option tag dynamically?

Here is the code

for (var i = 0; i < jsonArr.length; i++) {
    var obj = jsonArr[i];
    htmlText += '<option value="'+obj.place+'">' + placeName + '</option>';
}

I want to show Images as well as place name on the option tag dynamically?

from your question, you mentioned as

for(var i=0;i<jsonArr.length;i++){
                    var obj = jsonArr[i];
                    htmlText += '<option value="'+obj.place+'">'+placeName+'</option>';
                }

this is not possible, you need to use plugins

try this:

<option value="vaulue_in_integer" id="ID" style="background: url(imageName.png) right no-repeat; width: ABCpx; height: ABCpx">DEMO_TEXT</option>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM