close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
[data-state='grey']{
background-color: #eee;
}
[data-state='red']{
background-color: #f00;
}
</style>
</head>
<body>
<button id="btn" data-state='grey'>我是按鈕</button>
<script type="text/javascript">
document.getElementById('btn').onclick=function(e){
switch(e.target.getAttribute('data-state')){
case 'grey':
e.target.setAttribute('data-state','red');
break;
case 'red':
e.target.setAttribute('data-state','grey');
break;
}
}
</script>
</body>
</html>
全站熱搜
留言列表