gpt4 book ai didi

jQuery 改变复选框

转载 作者:行者123 更新时间:2023-12-01 08:20:32 25 4
gpt4 key购买 nike

我不确定更改方法是否正确使用。我想要的是,如果单击(选中)该复选框,则文本区域的 html 为 var 2,如果取消选中该复选框,则文本区域的 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>

最佳答案

使用.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);
}
});
});

关于jQuery 改变复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7629053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com