我有一個3X3盒子,目前我擁有它,這樣當您將鼠標懸停在任何一個方塊上時,背景變成藍色,然後當您將鼠標懸停在外時,盒子將恢復爲空。我也有它,這樣當任何一個方框被點擊時,一個圖像就會出現。我現在想要完成的是這樣做,當單擊框時,圖像將出現,當同一個框再次單擊時,圖像將消失,等等使用Jquery。當鼠標離開div時刪除圖像
以下是我有:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$('.divs').hover(function() {
$(this).css("background-color", "#0000EE");
console.log('hover');
}, function() {
$(this).css("background-color", "");
console.log('hoverout');
});
$('.divs').click(function() {
$(this).prepend("<img class='divimg' src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/SMirC-cool.svg/320px-SMirC-cool.svg.png>");
console.log('divclicked');
});
});
那麼你有什麼嘗試? – TJHeuvel