javascript 单击时如何突出显示html页面中的按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17747112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to highlight a button in html page when i click on it?
提问by user2595861
I have four buttons on the page, when I click on one of them i want it to be highlighted.
我在页面上有四个按钮,当我点击其中一个按钮时,我希望它突出显示。
The buttons are used to pass data to a controller. They are like this:
这些按钮用于将数据传递给控制器。他们是这样的:
<button name="region" id="region" type="button" onclick="window.location='/project/Viewdata/index/region/1'" class="current">ALL</button>
<button name="region" id="region2" type="button" onclick="window.location='/project/Viewdata/index/region/2'" class="current">1st</button>
回答by Jamie De Palmenaer
check this JSFiddle
检查这个JSFiddle
basically, you bind a highligt effect to the button with jQuery, when clicking it like this
基本上,当你像这样点击按钮时,你使用 jQuery 将一个高光效果绑定到按钮上
$('button').click(function() {
$(this).effect( "highlight", {color: 'red'}, 3000 );
});
NOTE: As said in the comments, you should never have 2 elements with the same id on one page. If you want to use the same descriptor, use class
instead of id
注意:正如评论中所说,你永远不应该在一个页面上有 2 个具有相同 id 的元素。如果要使用相同的描述符,请使用class
代替id