我正在尝试显示具有高图破折号的select元素。我需要在每个选项中显示dashstyle svg。
这是我的小提琴,只是为了更好地解释: http://jsfiddle.net/m2rqsx8e
如何使用jquery和/或bootrstap执行此操作?我在这里发现了类似的问题,但使用的是ExtJS。
代码:
<script src="http://code.highcharts.com/highcharts.js"></script>
<select id="container"> </select>
<script>
var renderer;
$(function () {
var dashStyles = [
'Solid',
'ShortDash',`enter code here`
'ShortDot',
'ShortDashDot',
'ShortDashDotDot',
'Dot',
'Dash',
'LongDash',
'DashDot',
'LongDashDot',
'LongDashDotDot'
];
$.each(dashStyles, function (i, dashStyle) {
$('#container').append('<option value="'+dashStyle+'"></option>');
renderer = new Highcharts.Renderer(
$('#container').find('option').last()[0],
200,
10
);
renderer.text(dashStyle, 10, 30 * i + 20)
.add();
renderer.path(['M', 10, 30 * i + 23, 'L', 390, 30 * i + 23])
.attr({
'stroke-width': 2,
stroke: 'black',
dashstyle: dashStyle
})
.add();
});
});
</script>
答案 0 :(得分:1)
我找不到办法。所以我所做的是使用jQuery plugin (ddslick)在下拉列表中渲染图像。我相信这不是最好的选择,但解决了我的问题,我会在这里作为替代方案。
代码是这样的:
<select for="dashstyle" id="dashStyles" name="dashStyle">
<option value="Solid" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/Solid.png") %>" ></option>
<option value="ShortDash" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/ShortDash.png") %>" ></option>
<option value="ShortDot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/ShortDot.png") %>" ></option>
<option value="ShortDashDot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/ShortDashDot.png") %>" ></option>
<option value="ShortDashDotDot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/ShortDashDotDot.png") %>" ></option>
<option value="Dot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/Dot.png") %>" ></option>
<option value="Dash" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/Dash.png") %>" ></option>
<option value="LongDash" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/LongDash.png") %>" ></option>
<option value="DashDot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/DashDot.png") %>" ></option>
<option value="LongDashDot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/LongDashDot.png") %>" ></option>
<option value="LongDashDotDot" data-imagesrc="<%= ResolveUrl("~/Content/img/lines/LongDashDotDot.png") %>" ></option>
</select>