2

这是解决问题的 JSFidle:http: //jsfiddle.net/LRTh3/36/

$('div.boxes').mousedown(function (event) {

    // Error on this line
    var inner_box = $(".box").is(":hover");

    if ( inner_box == true ) {

        alert("blue,gree,pink was clicked");
    }

    else alert("You mousedowned on the red box");

});​

console: Uncaught Error: Syntax error, unrecognized expression: hover 

如果只呈现一个“.box”层就可以工作。这是一个错误吗?我将如何解决这个问题?

4

1 回答 1

1
$('div.boxes').mousedown(function (event) {

// Error on this line
var $target = $(event.target);    
if (  $target.is(".box")) {

    alert("blue,gree,pink was clicked");
}

else alert("You mousedowned on the red box");


});​

我从jQuery API 文档中提取它

于 2012-05-22T14:45:21.227 回答