## js點擊事件
>效果如圖
>
(忽略左邊的黑線)

>html代碼
```
<p class="title">請為下面的div設置樣式: <span id="click">點擊設置</span></p>
<div id="test"></div>
<div id="setting">
<p>請選擇背景色:
<span id="red">紅</span>
<span id="yellow">黃</span>
<span id="blue">藍</span>
</p>
<p>請選擇寬(px):
<span id="w-2">200</span>
<span id="w-3">300</span>
<span id="w-4">400</span>
</p>
<p>請選擇高(px):
<span id="h-2">200</span>
<span id="h-3">300</span>
<span id="h-4">400</span>
</p>
<span id="reset">恢復</span>
<span id="makesure">確定</span>
</div>
```
>css代碼
```
* {
margin: 0;
padding: 0;
}
.title {
font-size: 25px;
font-weight: bold;
}
.title>span {
padding: 5px;
background: red;
color: #fff;
cursor: pointer;
}
#test {
width: 50px;
height: 50px;
margin-top: 40px;
border: 3px solid #ddd;
}
#setting {
position: fixed;
display: none;
top: 20%;
right: 40%;
padding: 10px;
font-size: 20px;
border: 5px solid #ccc;
}
#setting>p {
margin-bottom: 17px;
}
#setting span {
margin: 0 3px;
padding: 3px 10px;
cursor: pointer;
}
#setting span:hover {
background-color: aquamarine;
}
#setting>span {
background-color: cadetblue;
color: #fff;
}
#setting>p>span {
padding: 3px 10px;
background-color: #ddd;
}
```
>js代碼
```
window.onload = function(){
/*封裝$*/
var $ = function(id){
return document.getElementById(id);
}
var click = $("click");
click.onclick = function(){setting.style.display = "block";}
/*建立設置顏色,寬,高的函數*/
function c_color(id, color){
var dom = document.getElementById(id);
dom.style.backgroundColor = color;
}
function w_width(id, width){
var dom = document.getElementById(id);
dom.style.width = width + "px";
}
function h_height(id, height){
var dom = document.getElementById(id);
dom.style.height = height +"px";
}
/*為各個按鈕設置點擊動作*/
$("red").onclick = function(){c_color("test", "red");}
$("yellow").onclick = function(){c_color("test", "yellow");}
$("blue").onclick = function(){c_color("test", "blue");}
$("w-2").onclick = function(){w_width("test", 200);}
$("w-3").onclick = function(){w_width("test", 300);}
$("w-4").onclick = function(){w_width("test", 400);}
$("h-2").onclick = function(){h_height("test", 200);}
$("h-3").onclick = function(){h_height("test", 300);}
$("h-4").onclick = function(){h_height("test", 400);}
$("reset").onclick = function(){
$("test").style.width = 50 + "px";
$("test").style.height = 50 + "px";
$("test").style.backgroundColor = "#fff";
}
$("makesure").onclick = function(){
$("setting").style.display = "none";
}
}
```
----
整個demo已上傳至[github](https://github.com/MrXuxu/H5_demo/tree/master/JS%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6)
- 空白目錄
- css實用樣式
- css--下拉欄的幾種設計
- css--圖片陰影以及浮起的效果
- css--圖片翻轉二:自動翻轉
- css--圖片翻轉一:滑過翻轉
- css--三種loading特效
- css--圖片遮罩效果實現
- css--又是三種loading特效
- css--帶三角形的圖形實現
- js demo
- 原生demo
- 1. 原生js實現輪播圖
- 2. 倒計時按鈕
- 3. 動態添加表格
- 4. checkbox全選反選
- 5. 小米登錄方式切換
- 6. 點擊事件
- 7. 個人網頁導航條(二)點擊滾動
- 8. 瀑布流實現!
- 9. 個人網頁導航條(一)滑動固定
- 10. 定時器實現淡入淡出效果
- 11. 輪播圖setTimeout版
- jQuery demo
- 1. 輪播圖實現!
- 2. 成都小風車導航特效
- html組件
- html--導航欄(家居醫生)
- html--登錄頁面(小米登錄)
- html--響應式導航條(木兮地板)
- html--搜索欄
- Vue demo
- 1. mvvm實現動態添加表格
- 2. 豆瓣TOP250渲染
- 3. 制作一段跑馬燈文字
- 3.1. vue 單行文字自動跑馬燈效果
- 4. 利用豆瓣接口搜索書籍
- 5. 制作簡易計算器
- 6. 創建一個點贊組件
- 7. 列表添加刪除動畫
- 8. isShow手風琴原理
- 9. tab欄切換