欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

2、給類(lèi).question綁定點(diǎn)擊事件,在觸發(fā)函數(shù)里面先判斷當(dāng)前點(diǎn)擊的這個(gè)類(lèi)的id,即可知道你要操作的是哪一個(gè)問(wèn)題,然后調(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(){
//獲取問(wèn)題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ī)?lái)的在一個(gè)頁(yè)面重復(fù)使用一個(gè)js函數(shù)的方法詳解全部?jī)?nèi)容了,希望大家多多支持腳本之家~

相關(guān)文章

最新評(píng)論