Home > Web Front-end > JS Tutorial > How to implement JS control button color to change with click

How to implement JS control button color to change with click

巴扎黑
Release: 2018-05-22 11:51:31
Original
6095 people have browsed it

The following editor will bring you a simple JS control button color change method with clicks. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

First, the renderings:

The default is "Today" It is the selected state and the in-line style:

<button type="button" id="today" class="btn-link" onclick="todayDate()" style="color: #0062CC;">今日</button>
Copy after login

The above dates will switch colors only when clicked:

Click on other colors, "Today" "Change the color to gray

Click "Today" again to restore the default state color

Add a click event to any other date except "Today" to achieve [Change" "Today" default color status】

Add [Restore the default status color of "Today"] in the click event of "Today"

//昨日click
function yesterdayDate() {
  document.getElementById(&#39;title&#39;).value = getYesterdayDate(new Date());
  fetYesterdayData();
  today.css(&#39;color&#39;,&#39;#555555&#39;);
}
//今日click
function todayDate() {
  document.getElementById(&#39;title&#39;).value = formatterDateStr(new Date());
  fetTodayData();
  today.css(&#39;color&#39;,&#39;#0062cc&#39;);
}
Copy after login

OK, complete

The above is the detailed content of How to implement JS control button color to change with click. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template