jQuery:如何显示元素并同时使用高亮效果? [英] jQuery: How to show an element and use the highlight effect at the same time?
问题描述
我在页面上有两个元素。
I have two elements on a page.
<div id="a">content</div>
<div id="b" style="display:none">different content</div>
当我点击当前显示的 div
时,我想隐藏它并显示另一个。这很容易做到:
When I click the currently displayed div
, I want to hide it and show the other one. This is easy to do:
$('#a').hide();
$('#b').show();
但现在我想更进一步,突出显示元素。我认为它将涉及效果(突出显示)
,但我无法让它发挥作用。我如何实现这一目标?
But now I want to take it a step further and highlight the element as it is being displayed. I think that it will involve effect("highlight")
, but I can't get it to work. How do I achieve this?
推荐答案
首先要纠正您的ID属性。它们不允许以数字开头。
First thing is to correct your ID attributes. They are not allowed to start with a number.
鉴于此,您可能只需要加载jQueryUI。该效果需要有效。
Given that, you probably just need to load jQueryUI. It is required for that effect to work.
http: //jqueryui.com/demos/effect/
以下是一个例子: http://jsfiddle.net/r6pKn/
HTML
<div id="div1">content</div>
<div id="div2" style="display:none">different content</div>
jQuery
$('#div1').click(function() {
$(this).hide();
$('#div2').show().effect('highlight');
});
这篇关于jQuery:如何显示元素并同时使用高亮效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!