简体   繁体   English

JQuery - “突出”效果的帮助

[英]JQuery - “highlight” effect help

Looking at the "highlight" JQuery effect: 看看“突出”JQuery效果:

http://docs.jquery.com/UI/Effects/Highlight http://docs.jquery.com/UI/Effects/Highlight

You can change the background color of any DIV to fade in/out 您可以将任何DIV的背景颜色更改为淡入/淡出

However, the example is to "highlight" on a "click" event 但是,该示例是“突出显示”“点击”事件

$("div").click(function () {
      $(this).effect("highlight", {}, 3000);
});

How can I programatically call the highlight method as though it was a function within my code (instead of activate on a 'click' event)? 我如何以编程方式调用高亮方法,就好像它是我的代码中的一个函数(而不是在'click'事件上激活)?

$("div").effect("highlight", {}, 3000);

As pointed by JorenB this will highlight all the div's in your page. 正如JorenB所指出的,这将突出显示页面中的所有div。

If you only want to highlight one div like: 如果您只想突出显示一个div:

<div id="myDiv"></div>

You should do: 你应该做:

$("div#myDiv").effect("highlight", {}, 3000);

If you want to highlight all div's with a specific classe you cand do: 如果你想突出显示具有特定classe的所有div,你可以做到:

<div id="myDiv1" class="myClass"></div>
<div id="myDiv2" class="myClass"></div>

$("div.myClass").effect("highlight", {}, 3000);

For more information on selectors see JQuery Selectors . 有关选择器的更多信息,请参阅JQuery选择器

它就是这样

$([your selector]).effect("highlight", {}, 3000);

You can also achieve that by triggering the click event, if you have that in your click handler anyway: 你也可以通过触发click事件来实现这一点,如果你在你的点击处理程序中有这个:

$('div').click();

or: 要么:

$('div').trigger('click');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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