描述:用一個(gè)div寫(xiě)一個(gè)按鈕陡蝇,并給這個(gè)按鈕添加一個(gè)點(diǎn)擊事件,在安卓機(jī)器上一切正常,但是在蘋(píng)果機(jī)型上會(huì)出現(xiàn)點(diǎn)擊事件失效十饥。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.redButton{
width: 50px;
height: 50px;
background: red;
text-align: center;
line-height: 50px;
}
</style>
</head>
<body>
<div class="button">
<div class="redButton">
按鈕
</div>
</div>
<script src="jquery-3.0.0.min.js"></script>
<script>
$(document).on("click",".redButton",function(){
alert('點(diǎn)擊了按鈕');
});
</script>
</body>
</html>
解決蘋(píng)果機(jī)點(diǎn)擊失效代碼:
為什么會(huì)出現(xiàn)這個(gè)問(wèn)題:蘋(píng)果機(jī)對(duì)于點(diǎn)擊的對(duì)象丧蘸,要擁有cursor:pointer這個(gè)樣式的設(shè)置漂洋,也就是說(shuō),鼠標(biāo)放上去力喷,能夠出現(xiàn)“手”型的圖標(biāo)才被認(rèn)作可以使用點(diǎn)擊事件刽漂,然后就加一行css咯~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.redButton{
width: 50px;
height: 50px;
background: red;
text-align: center;
line-height: 50px;
cursor:pointer; //光標(biāo)呈現(xiàn)為指示鏈接的指針
}
</style>
</head>
<body>
<div class="button">
<div class="redButton">
按鈕
</div>
</div>
<script src="jquery-3.0.0.min.js"></script>
<script>
$(document).on("click",".redButton",function(){
alert('點(diǎn)擊了按鈕');
});
</script>
</body>
</html>