jQuery更改复选框
我不确定更改方法是否正确。我想要的是,如果选中该复选框,则textarea的html为var 2,如果未选中该复选框,则textarea的html为var 1。我如何做到这一点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
<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分钟的超时时间。我错了!只是想帮忙:)