JSFiddle - React, Tailwind, and code Playground
by wllai2001
HTML
<div data-clickcount="0" style="cursor: pointer;">-點我-</div>
<br/>
<div class="msg">點擊次數累計:0</div>
CSS
div{
background:#ccc;
}
JavaScript
/*點擊換色測試*/
$("div").click(function(){
var $this = $(this);
var $msg = $(".msg");
switch($this.data("clickcount")) {
case 0:
$this.data( "clickcount", $this.data("clickcount")+1 ); break;
case 1:
$this.css("background","red");
$this.data( "clickcount", $this.data("clickcount")+1 );
break;
default:
$this.css("background","#ccc");
$this.data( "clickcount", 0 );
}
$msg.html("點擊次數累計:"+$this.data("clickcount"));
});