gpt4 book ai didi

javascript - 如果我取消选中该复选框以及如果我选中按 (", "分割,如何打印空白)

转载 作者:行者123 更新时间:2023-12-03 05:32:56 29 4
gpt4 key购买 nike

<ul class="dropdown-menu">
<li><a href="#" class="small" data-value="1" tabindex="-1">
<input type="checkbox" id="Speaker1" class="chkCris" value="1" />1</li>
<li><a href="#" class="small" data-value="2" tabindex="-1">
<input type="checkbox" id="Speaker2" class="chkCris" value="2" />2</a> </li>
<li><a href="#" class="small" data-value="6" tabindex="-1">
<input type="checkbox" id="chkOthers" class="chkCriOthers" value="Others" />&nbsp;Others, please explain</a> </li>
<li><div id="divOthers" style="display: none; font-size: 14px; text-align: left;"><a id="A1" href="#" class="small" data-value="7" tabindex="-1">
<input class="input-xxlarge" id="textboxOthers" name="textboxOthers" type="text" placeholder="Others, please explain" ></a>
</div>
</li>
</ul>

function getValueCriteriaSpeaker()
{
/* declare an checkbox array */
var chkArray = [];
$(".chkCris:checked").each(function () {
chkArray.push($(this).val());
});

if (document.getElementById("chkOthers").checked == true)
{
var otherscriteria = document.getElementById("textboxOthers").value;
chkArray.push(otherscriteria);
}

// ....

那么如果我取消选中复选框如何打印空白?例如:对于值 2 取消选中(打印空白)-> 1, , other

最佳答案

虽然问题不是很清楚,但这是我对您的问题的实现

function getValueCriteriaSpeaker(){
var values = $("ul.dropdown-menu :checkbox:checked").map(function(i,cb){ return $(cb).val();});
var str = values.get().join($('#useComma').is(':checked') ? ',' : ' ');

$('#textboxOthers').val(str);
}

$('.chkBox').on('change',getValueCriteriaSpeaker)
$('#useComma').on('change',getValueCriteriaSpeaker)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>
<input type="checkbox" id="useComma"/>
Split By "," (Comma)
</span>
<ul class="dropdown-menu">
<li><input type="checkbox" id="Speaker1" class="chkBox" value="1" />1</li>
<li><input type="checkbox" id="Speaker2" class="chkBox" value="2" />2</li>
<li><input type="checkbox" id="chkOthers" class="chkBox" value="Others">Others</li>
<li>
<div id="divOthers">
<input class="input-xxlarge" id="textboxOthers" name="textboxOthers" type="text" placeholder="Others, please explain"/>
</div>
</li>
</ul>

关于javascript - 如果我取消选中该复选框以及如果我选中按 (", "分割,如何打印空白),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40859827/

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