Javascript 跟踪取消选择无线电
有没有一种方法可以跟踪取消选中的无线电元素Javascript 跟踪取消选择无线电,javascript,jquery,html,Javascript,Jquery,Html,有没有一种方法可以跟踪取消选中的无线电元素 <script type="text/javascript"> $().ready(function() { $('#answer-1').change(function(){ console.log('radio-1 changed'); }); $('#answer-2').change(function(){ console.log('radio-2 changed');
<script type="text/javascript">
$().ready(function() {
$('#answer-1').change(function(){
console.log('radio-1 changed');
});
$('#answer-2').change(function(){
console.log('radio-2 changed');
});
});
</script>
<input name="question-1" type="radio" id="answer-1" />Value
<input name="question-1" type="radio" id="answer-2" />Value
$().ready(函数()){
$('#答案-1')。更改(函数(){
console.log('radio-1已更改');
});
$('#答案-2')。更改(函数(){
console.log('radio-2已更改');
});
});
价值
价值
预期结果:选择应答-1时,显示事件“radio-1已更改”,然后切换到应答-2时,应显示radio-2已更改和radio-1已更改
实际结果:选择应答-1时,显示事件“radio-1已更改”,然后切换到应答-2时,仅显示“radio-2已更改”
取消选择收音机时,有没有办法获取事件?试试这个
<script type="text/javascript">
$().ready(function() {
$('input[name=question-1]').change(function(){
if(this.checked)
console.log('radio is selected');
else
console.log('radio is note selected');
});
});
</script>
$().ready(函数()){
$('input[name=question-1]')。更改(函数(){
如果(选中此项)
console.log(“选择了无线电”);
其他的
console.log('选择了收音机注释');
});
});
试试这个
<script type="text/javascript">
$().ready(function() {
$('input[name=question-1]').change(function(){
if(this.checked)
console.log('radio is selected');
else
console.log('radio is note selected');
});
});
</script>
$().ready(函数()){
$('input[name=question-1]')。更改(函数(){
如果(选中此项)
console.log(“选择了无线电”);
其他的
console.log('选择了收音机注释');
});
});
您可以使用.data
这是一把可以帮助你使用
.data
这把小提琴可能有用