我工作的一個腳本,不知道爲什麼這是不工作檢測可變的屬性 - jQuery的
function moveIn($selector) {
if($($selector[left]) != null){
$direction = 'left';
}else{
$direction = 'right';
}
這是沒有問題:
if($('#hello[left]') != null){
實際上,這就是我想吐出來。看起來括號導致了問題。這還會寫成什麼呢?未來編碼技巧? 感謝
全功能:
function moveIn($selector) {
if($($selector + '[left]') != null){
$direction = 'left';
}else{
$direction = 'right';
}
var animation = {};
animation[$direction] = 0;
$($selector).animate(animation, 1500);
}
提示,你不應該把'$'放在* * * *之前,它可能有一些有用的,如果它是一個jQuery對象。 –