为了账号安全,请及时绑定邮箱和手机立即绑定

如何在点击事件 jquery 中使用点击事件

如何在点击事件 jquery 中使用点击事件

慕妹3242003 2022-09-23 21:57:55
我有一个生成的列表,因此它可以包含任何数量的问题。总有三个答案,"OK", "Fout" and "N.v.t."当 被选中时(fout在荷兰语中表示错误),将显示一个下拉列表,其中可以添加其他信息和图像。fout我为它做了相同的工作,但现在我只想在点击加号图标时显示该下拉列表。此图标仅在用户使用 回答问题后显示。OKOK你可以在这里看到它:https://jsfiddle.net/6pxjskr5/我该怎么做?我的猜测是内部的,但我不知道这是否可能。click eventclick event我尝试了以下方法:$(document).on('click', '[id^=radio]', function(){  var userresp = this.value;  var fout_id = $(this).attr('id');  var index = fout_id.split('-')[1];  if (userresp == 'ok') index= parseInt(index)+ 1;  if (userresp == 'fout') index= parseInt(index)+ 0;  if (userresp == 'nvt') index= parseInt(index)- 1;  // The container for the additional negative info (FOUT)  var afw_id = 'afw-div-' + index;  // The container for the additional positive info (OK)  var pos_id = 'pos-div-' + index;  // The plus icon  var plus_id = 'plus-div-' + index;    console.log('radio clicked', userresp, index);    if (userresp=='fout') {        $('#' + afw_id).slideDown();        $('#' + pos_id).slideUp();        $('#' + plus_id).hide();    }    else if(userresp=='ok'){        $('#' + afw_id).slideUp();        $('#' + plus_id).show();        $(document).on('click', plus_id, function(){          console.log('test');        });    }else{        $('#' + plus_id).hide();        $('#' + afw_id).slideUp();        $('#' + pos_id).slideUp();    }});但是,单击加号图标时,我的控制台中没有消息。test
查看完整描述

1 回答

?
慕沐林林

TA贡献2016条经验 获得超9个赞

例如,您的选择器等于 。但是您打算按 ID 进行选择,因此应以 .所以它变成了:.plus_idplus-div-123##plus-div-123



查看完整回答
反对 回复 2022-09-23
  • 1 回答
  • 0 关注
  • 61 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信