![](/img/trans.png)
[英]Is there a reason why my check mark box won't be selected when I click the span tag?
[英]Why won't my span do a JQuery event click when I click it?
.tablePlayButton {
display: block;
width: 16px;
background: transparent;
margin-top:2px;
margin-right: -10px;
margin-left: 2px;
height:17px;
}
tr:hover .tablePlayButton {
background: url(ton.png) top left no-repeat;
}
tr:hover .tablePlayButton:active {
background-position: bottom left;
}
tr:hover .tablePlayButton.playing,
.tablePlayButton.playing {
background: url(ton2.png) top right no-repeat;
}
tr:hover .tablePlayButton.playing:active,
.tablePlayButton.playing:active {
background-position: bottom right;
}
我這樣繪制跨度: <span class="tablePlayButton"></span>
它有一個小按鈕。 當我單擊它時,沒有任何反應:
$(".tablePlayButton").click(function(){
alert('hi');
});
您可能在創建元素之前添加了點擊處理程序。
嘗試將Javascript代碼移動到元素之后,或將其包裝在$(function() { ... });
使它在文檔加載后運行。
改寫為
$(document).ready(function() {
$(".tablePlayButton").click(function() {
alert('hi');
});
});
里面有文字嗎? 對於一個內聯元素,你通常需要點擊里面可見的東西 。 更改跨度,使其具有文本“ SPAN”,然后查看是否可以單擊它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.