Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery更改复选框_Jquery - Fatal编程技术网

jQuery更改复选框

jQuery更改复选框,jquery,Jquery,我不确定更改方法是否正确。我想要的是,如果选中该复选框,则textarea的html为var 2,如果未选中该复选框,则textarea的html为var 1。我如何做到这一点 <script type="text/javascript"> $(function() { $('.image').change(function() { var one='type information here'; var two='type url here'; if($('.informat

我不确定更改方法是否正确。我想要的是,如果选中该复选框,则textarea的html为var 2,如果未选中该复选框,则textarea的html为var 1。我如何做到这一点

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

$(函数(){
$('.image').change(函数(){
var one='type information here';
var two='type url here';
if($('.information').html=='type information here'){
$('.information').html('type url here');
}否则{
$('.information').html('type information here');
}
});
});
在此处键入信息
使用
.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);
        }
    });
});

您需要使用JSFIDLE。用你的例子做一个JSFIDLE,然后我会帮你,如果解决了你的问题,请将解决方案标记为答案:)@grailsgay在接受答案之前有15分钟的超时时间。我错了!只是想帮忙:)