开发者

jQuery change of checkbox

I'm not sure if the change method is 开发者_运维百科the correct to use. What i want is if the checkbox is clicked(checked) the html of the textarea is var two and if the checkbox is unchecked the html of the textarea is var one. How do i accomplish this?

<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>


Use .val() instead of .html(). Also, notice that you've forgot the parentheses in your if-condition.

$(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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜