[英]jQuery Highlight element on select option
I have a list of values in a drop down style select box eg 我在下拉样式选择框中有一个值列表,例如
<select id="places">
<option>Italy</option>
<option>France</option>
<option>Germany</option>
<option>Spain</option>
</select>
I also have the same list of values in a div on my page eg 我的页面上的div中也有相同的值列表,例如
<div>
<span>Italy</span>
<span>France</span>
<span>Germany</span>
<span>Spain</span>
</div>
Using JQuery, I want to have it so - when a value in the dropdown is selected, the equivalent option in the div is briefly highlighted. 使用JQuery,我想拥有它-在下拉列表中选择一个值时,将简要突出显示div中的等效选项。
I've been struggling with the jQuery highlight plugin, but I believe the quicker way may be to use the highlight class of JjQuery UI. 我一直在努力使用jQuery Highlight插件,但是我相信更快的方法可能是使用JjQuery UI的Highlight类。 Apologies in advance for being a noob :)
预先为菜鸟道歉:)
Using the highlight effect from jQuery UI : 使用jQuery UI的高亮效果 :
$('#places').change(function() {
$('div span:contains(' + $(this).val() + ')').effect('highlight', {}, 1000)
})
When an item from the drop-down is selected, the span containing the respective text of the selected item is run through a animation of its background color ("highlight" effect) provided by the plugin. 当从下拉列表中选择一个项目时, 包含 所选项目各自文本的跨度将通过插件提供的背景颜色动画(“突出显示”效果)运行。
Using JQuery UI plugin you can use the following 使用JQuery UI插件,您可以使用以下内容
$('#places').change(function(){
$('span:contains('+ $(this).val() +')').effect('highlight', {color: 'red'}, 3000);
});
Change the color and 3000 as required. 根据需要更改颜色和3000。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.