亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

在一個(gè)頁面重復(fù)使用一個(gè)js函數(shù)的方法詳解

 更新時(shí)間:2016年12月26日 10:47:57   投稿:jingxian  
下面小編就為大家?guī)硪黄谝粋€(gè)頁面重復(fù)使用一個(gè)js函數(shù)的方法詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,祝大家游戲愉快哦

1、給每個(gè)擁有相同行為的問題DOM節(jié)點(diǎn)一個(gè)相同的class類,如question,同時(shí)給不同的問題一個(gè)不同的標(biāo)識(shí)ID如 id="question1" id="question2"...諸如此。

2、給類.question綁定點(diǎn)擊事件,在觸發(fā)函數(shù)里面先判斷當(dāng)前點(diǎn)擊的這個(gè)類的id,即可知道你要操作的是哪一個(gè)問題,然后調(diào)用你的那個(gè)伸縮函數(shù)即可。

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jQuery加法器</title>
<script src="js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
<style>
div {
width: 250px;
height: 250px ;
background-color: #337ab7;
float:left;
margin: 10px;
}
</style>
</head>
<script>
$(function(){
$(".question").click(function(){
//獲取問題ID
var id = $(this).attr("id");
//console.log(id)
//...執(zhí)行你的函數(shù)代碼
})
})
</script>
<body>
<div class="question" id="question1"></div>
<div class="question" id="question2"></div>
<div class="question" id="question3"></div>
<div class="question" id="question4"></div>
</body>
</html>

以上就是小編為大家?guī)淼脑谝粋€(gè)頁面重復(fù)使用一個(gè)js函數(shù)的方法詳解全部內(nèi)容了,希望大家多多支持腳本之家~

相關(guān)文章

最新評(píng)論