用jquery寫的 為什么找不到 mouseover這個函數呢?
jQuery(document).ready(function() {
?? ?var t = $(".dox li"),
?? ??? ?b = $(".dox div");
?? ?if (t.length != b.length) return;
?? ?for (var i = 0; i < t.length; i++) {
?? ??? ?t[i].id = i;
?? ??? ?t[i].mouseover(function() {
?? ??? ??? ?for (var j = 0; j < b.length; j++) {
?? ??? ??? ??? ?b.css("display", "none");
?? ??? ??? ??? ?t.addClass('tt');
?? ??? ??? ?};
?? ??? ??? ?console.log(this);
?? ??? ??? ?t[i].addClass('hover');
?? ??? ??? ?b[this.id].css("display", "block");
?? ??? ?});
?? ?};
});
2015-07-20
你可以了解一下 jquery對象如何轉化為DOM對象, 就是通過$('p')[0] 這樣,
所以你 取值之后他就應該是一個DOM對象了,而DOM對象是沒有你寫的這些方法的。
所以你變了數組應該這樣
2015-07-20
jQuery(document).ready(function() {
?? ?var t = $(".dox li"),
?? ??? ?b = $(".dox div");
?? ?if (t.length != b.length) return;
?? ?for (var i = 0; i < t.length; i++) {
?? ??? ?t[i].id = i;
?? ??? ?// console.log($(t[i]));
?? ??? ?$(t[i]).mouseover(function() {
?? ??? ??? ?for (var j = 0; j < b.length; j++) {
?? ??? ??? ??? ?b.css("display", "none");
?? ??? ??? ??? ?t.removeClass();
?? ??? ??? ?};
?? ??? ??? ?console.log(this);
?? ??? ??? ?console.log(this.id);
?? ??? ??? ?$(this).addClass('hover');
?? ??? ??? ?$(b[this.id]).css("display", "block");
?? ??? ?});
?? ?};
});
//完整的代碼
2015-07-20
是onmouseover~