【问题标题】:How to highlight a button in html page when i click on it?当我点击它时如何突出显示html页面中的按钮?
【发布时间】:2013-07-19 13:17:43
【问题描述】:

我在页面上有四个按钮,当我点击其中一个时,我希望它突出显示。

按钮用于将数据传递给控制器​​。 他们是这样的:

<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>

【问题讨论】:

  • 你不能有两个具有相同 id 的元素!
  • 按钮有重定向代码。他们不会在点击后重定向吗?
  • 是的,这是我面临的一个问题,因为重定向选项它加载了基本设置
  • 有什么理由不使用普通链接?
  • 我改变了 id 的 :)

标签: javascript jquery html php


【解决方案1】:

检查这个JSFiddle

基本上,当像这样单击它时,您可以使用 jQuery 将高亮效果绑定到按钮

$('button').click(function() {
    $(this).effect( "highlight", {color: 'red'}, 3000 );
});

注意:正如 cmets 中所说,您永远不应该在一页上有 2 个具有相同 id 的元素。如果要使用相同的描述符,请使用class 而不是id

【讨论】:

  • 之前尝试过同样的方法......但它没有工作......我已经更改了id但仍然没有结果......
猜你喜欢
  • 1970-01-01
  • 2014-10-08
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
  • 2023-03-05
  • 1970-01-01
相关资源
最近更新 更多