jquery
2011-10-02 135 views 1 likes 
1

我不確定更改方法是否正確使用。我想要的是,如果複選框被點擊(選中),textarea的html是var 2,如果複選框未被選中,textarea的html是var一個。我如何做到這一點?jQuery更改複選框

<script type="text/javascript"> 
$(function() { 


$('.image').change(function() { 
var one='type information here'; 
var two='type url here'; 

if($('.information').html=='type information here') { 
$('.information').html('type url here'); 
} else { 
$('.information').html('type information here'); 
} 

}); 



}); 
</script> 


<input type="checkbox" class="image"/> 
<textarea class="information">type information here</textarea> 
+0

您需要使用jsfiddle。用你的例子做一個jsfiddle,然後我會幫你 –

回答

3

使用.val(),而不是.html()。此外,請注意,您忘記了if條件中的括號。

$(function() { 
    $('.image').change(function() { 
     var one='type information here'; 
     var two='type url here'; 

     if($('.information').val() == one) { 
      $('.information').val(two); 
     } else { 
      $('.information').val(one); 
     } 
    }); 
}); 
+0

如果它解決了你的問題,請將解決方案標記爲答案:) – Igor

+0

@GrailsGuy在答案被接受之前有15分鐘的超時時間。 –

+0

我的錯誤!只是想幫助:) – Igor

相關問題