隐藏动态创建的单选按钮组件

时间:2022-12-22 20:37:46

When I click in one of the table cells, radio buttons appear. when i click on other cell and select the option, radio button component is getting shown for the first cell which should not be shown/displayed.Please suggest where i'm going wrong.

当我单击其中一个表格单元格时,会出现单选按钮。当我点击其他单元格并选择该选项时,单选按钮组件将显示第一个不应显示/显示的单元格。请指出我哪里出错了。

Sample code below:

示例代码如下:

function showData(index, id, name){
    var rOptions = document.getElementById("options");
    if (rOptions == null){
      //logic
}       

   $('.one').live('click', function() {
     if($(this).hasClass("one")) {       
        deselect(index, name);  
     } 
 });
}

Please suggest.

1 个解决方案

#1


1  

you are adding an event listener everytime you're clicking on your cell.

每次点击单元格时都要添加一个事件监听器。

You could use $(app).die(); and $('.one').die(); to erase the listeners every time but I would recommend refactoring some code.

你可以使用$(app).die();和$('。one')。die();每次擦除听众,但我会建议重构一些代码。

You should be consistent in use of your selectors...either use jquery or don't.

您应该始终使用您的选择器...使用jquery或不使用。

Also pull out your eventListener Attachment.

同时拉出你的eventListener附件。

$("[id^=app]").on('click', function(event) {
    console.log("This is my name: "+this.name);
});

should do the trick. You can use an encoded ID to store your ID, name and whatever and parse them when the event happens so that you have one generic event for all cells.

应该做的伎俩。您可以使用编码的ID来存储您的ID,名称等等,并在事件发生时解析它们,以便您为所有单元格创建一个通用事件。

You should also consider using a newer version of jquery.

您还应该考虑使用更新版本的jquery。

#1


1  

you are adding an event listener everytime you're clicking on your cell.

每次点击单元格时都要添加一个事件监听器。

You could use $(app).die(); and $('.one').die(); to erase the listeners every time but I would recommend refactoring some code.

你可以使用$(app).die();和$('。one')。die();每次擦除听众,但我会建议重构一些代码。

You should be consistent in use of your selectors...either use jquery or don't.

您应该始终使用您的选择器...使用jquery或不使用。

Also pull out your eventListener Attachment.

同时拉出你的eventListener附件。

$("[id^=app]").on('click', function(event) {
    console.log("This is my name: "+this.name);
});

should do the trick. You can use an encoded ID to store your ID, name and whatever and parse them when the event happens so that you have one generic event for all cells.

应该做的伎俩。您可以使用编码的ID来存储您的ID,名称等等,并在事件发生时解析它们,以便您为所有单元格创建一个通用事件。

You should also consider using a newer version of jquery.

您还应该考虑使用更新版本的jquery。