[英]How to insert <img> tag inside <option> tag?
I want to display an image file from the data I passed from Controller to JSP. 我想显示我从Controller传递到JSP的数据中的图像文件。
For example, when you send the following value from JSP, 例如,当您从JSP发送以下值时,
{selectDoctor=[{d_name=MyName, d_imageServerPath=/boardFile/014e40e0ea.PNG, d_imagePath=C:/rachel/014e40e0ea.PNG, di_idx=2, d_imageOriginalName=testImage.PNG, d_idx=2, d_medicalInformation=valuevalue}]}
I have been able to display the value outside the tag through the statement. 我已经能够通过该语句在标签外部显示值。
<c:forEach items="${selectDoctor}" var="sD">
<select>
<option value="">Choice Doctor</option>
<option value="${sD.d_idx}"><img src="${sD.di_imageServerPath}></img>${sD.d_name}</option>
</select>
</c:forEach>
But unlike my expectations, the img tag does not work. 但是与我的期望不同,img标签不起作用。
How do I insert the tag inside the tag? 如何将标签插入标签内?
You cannot insert tag
within <option>
. 您不能在<option>
插入tag
。 Options
tags cannot contain any other tags. Options
标签不能包含任何其他标签。 Try to build you own dropdown
using <dd>
<dl>
tags
. 尝试使用<dd>
<dl>
tags
构建您自己的dropdown
。
Source Link http://jqueryui.com/selectmenu/#custom_render 源链接http://jqueryui.com/selectmenu/#custom_render
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Selectmenu - Custom Rendering</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $( function() { $.widget( "custom.iconselectmenu", $.ui.selectmenu, { _renderItem: function( ul, item ) { var li = $( "<li>" ), wrapper = $( "<div>", { text: item.label } ); if ( item.disabled ) { li.addClass( "ui-state-disabled" ); } $( "<span>", { style: item.element.attr( "data-style" ), "class": "ui-icon " + item.element.attr( "data-class" ) }) .appendTo( wrapper ); return li.append( wrapper ).appendTo( ul ); } }); $( "#filesA" ) .iconselectmenu() .iconselectmenu( "menuWidget" ) .addClass( "ui-menu-icons" ); $( "#filesB" ) .iconselectmenu() .iconselectmenu( "menuWidget" ) .addClass( "ui-menu-icons customicons" ); $( "#people" ) .iconselectmenu() .iconselectmenu( "menuWidget") .addClass( "ui-menu-icons avatar" ); } ); </script> <style> h2 { margin: 30px 0 0 0; } fieldset { border: 0; } label { display: block; } /* select with custom icons */ .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item-wrapper { padding: 0.5em 0 0.5em 3em; } .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item .ui-icon { height: 24px; width: 24px; top: 0.1em; } .ui-icon.video { background: url("images/24-video-square.png") 0 0 no-repeat; } .ui-icon.podcast { background: url("images/24-podcast-square.png") 0 0 no-repeat; } .ui-icon.rss { background: url("images/24-rss-square.png") 0 0 no-repeat; } /* select with CSS avatar icons */ option.avatar { background-repeat: no-repeat !important; padding-left: 20px; } .avatar .ui-icon { background-position: left top; } </style> </head> <body> <div class="demo"> <form action="#"> <h2>Selectmenu with custom avatar 16x16 images</h2> <fieldset> <label for="people">Select a Person:</label> <select name="people" id="people"> <option value="1" data-class="avatar" data-style="background-image: url('http://www.gravatar.com/avatar/b3e04a46e85ad3e165d66f5d927eb609?d=monsterid&r=g&s=16');">John Resig</option> <option value="2" data-class="avatar" data-style="background-image: url('http://www.gravatar.com/avatar/e42b1e5c7cfd2be0933e696e292a4d5f?d=monsterid&r=g&s=16');">Tauren Mills</option> <option value="3" data-class="avatar" data-style="background-image: url('http://www.gravatar.com/avatar/bdeaec11dd663f26fa58ced0eb7facc8?d=monsterid&r=g&s=16');">Jane Doe</option> </select> </fieldset> </form> </div> </body> </html>
实现此目的的最简单方法是使用jQuery的Select2插件,它提供了更多功能,您可以检查文档链接 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.