2014-04-09 28 views
-1

試圖通過jquery在表單條目正確的情況下設置樣式的更改 無法真正使其工作。 這裏是一個小提琴通過jquery動態改變表單條件上的樣式

<div id="protectimages"> 
Image Library Password 
<input class="libaccess" type="password" name="pwd"></input> 
<a class="libenter" href="#">enter</a> 
</div> 

和jQuery

$(document).ready(function(){ 
$("libenter").click(function(){ 

if ($(".libaccess").val() != test) { 
    $(".protectimages").css('background-color','f6f6f6'); 
} 

}); 
}); 

哪裏是我的錯?

編輯所有意見波紋管。這裏是小提琴 http://jsfiddle.net/soloveich/LvXb2/2/

+0

' 「libenter」' - >' 「.libenter」',' 'f6f6f6'' - >'' #f6f6f6'',大概'測試' - >''測試「'。但我也必須說,我希望你不打算使用客戶端密碼驗證。任何人都可以查看頁面的來源並找到密碼,或者完全繞過驗證。 –

+0

啊,'.protectimages' - >'#protectimages'。 http://jsfiddle.net/e64Ls/。我會通過http://learn.jquery.com –

+0

nope來看看。沒有去.... – user3353748

回答

0
put this code in your <head> :- 
    <head> 
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script> 
    $(document).ready(function(){ 
    $(".libenter").click(function(){ 

    if ($(".libaccess").val() != "test") { 
     $("#protectimages").css('background-color','#f6f6f6'); 
    } 

    }); 
}); 
</script> 
</head> 

You missed to call the click event by class ".libenter". One more thing "test" should be in string form. 

而且使用DIV 「#protectimages」 的ID。你還沒有提供jQuery庫的參考。不使用jQuery庫,你不能使用$。

+0

還是沒有去.... – user3353748

0

根據您上次編輯提琴http://jsfiddle.net/soloveich/LvXb2/2/,我回答

變化$(".protectimages")$("#protectimages")

if ($(".libaccess").val() != test) {if ($(".libaccess").val() != 'test') {

嘗試

$(document).ready(function() { 
    $(".libenter").click(function() { 

     if ($(".libaccess").val() != 'test') { 
      $("#protectimages").css('background-color', '#f6f6f6'); 
     } 

    }); 
}); 

http://jsfiddle.net/tamilcselvan/LvXb2/4/

注:在你的小提琴添加的jQuery