2013-03-18 60 views
0

我已经为我的网站添加了动态下拉搜索菜单。如果你转到我提供的链接,你会注意到左边有2个链接,表格选项中的javascript添加/删除行可以正常工作,直到我将class="chzn-select"(动态搜索菜单)添加到下拉菜单。会发生什么情况是,当添加类时,由于某种原因,不再添加新行。添加/删除行的css

在左侧的菜单上,您可以单击以查看操作中的NoCSS表以及包含class="chzn-select"的问题CSS表。我认为问题在于该菜单的css是动态的,取决于菜单处于哪种状态,但无法确定问题出在哪里。感谢所有帮助..

链接进行测试:http://directa.sytes.net/test/用户: TEST1 通行证: test1的

添加/删除使用脚本:jsfiddle.net/frtrc

感谢

我将粘贴CSS代码在这里,但该网站一直说,它包含代码,不会让我发帖,无论我如何格式化..:\

+0

你应该在这里发布你的代码那些其他链接有可能在一天内死亡。 – jmeas 2013-03-18 11:53:41

+0

我会的,但真的很多,它只会阻塞帖子,这就是为什么我提供实时网站看到它在行动。 – targsx 2013-03-18 11:57:41

回答

0

问题来自插件,它使用搜索栏创建样式下拉菜单(适用于“选择国家/地区”)。

它显示用于过滤国家/地区列表的输入字段。问题在于这个输入字段没有id-attribute,所以当下面的代码被执行时,它没有任何id来拆分,并且数组将是空的。

$tr.find("input,select").attr("name", function() 
{ 
    // break the field name and it's number into two parts 
    var parts = this.id.match(/(\D+)(\d+)$/); 
    // create a unique name for the new field by incrementing 
    // the number for the previous field by 1 
    return parts[1] + ++parts[2]; 
    // repeat for id attributes 
}).attr("id", function(){ 
    var parts = this.id.match(/(\D+)(\d+)$/); 
    return parts[1] + ++parts[2]; 
}); 

解决方法是首先确保有一个id要拆分。有关这里的更多信息:

Select elements by attribute

而且,你clickMe() - 函数不捕onclick -event不会起任何作用,并产生一个错误。

+0

感谢您指出问题,但林不知道从哪里开始。你能否给我一些指示什么需要做,实际上哪一部分需要改变? – targsx 2013-03-18 13:11:46

+0

好吧,如果你想重组或改变你的解决方案,一个简单的建议是确保文本框有一个ID。试试把这个放在你的就绪函数中:$(“.chzn-search”)。find(“input”)。attr(“id”,“searchbox1”); – ahdaniels 2013-03-18 13:32:53

+0

我更新了上面的链接,但仍然一样..其他建议? – targsx 2013-03-18 14:02:29

1

问题是当您使用生成后选择选项dyanamically新的div chosen.jquery.min.js和choose.css,让时间的JavaScript不起作用 $ tr.find(“输入,选择”)。 ATTR( “名”,()的函数,因为只有两个标签中增加了输入和选择

我建议添加JavaScript行

$(document).ready(function($) 
    { 
     $('#sif_roba1').next('div').attr("id","sif_roba1");//Chane Code 
     $('#sif_roba1').next('div').attr("name","sif_roba1"); 
     // trigger event when button is clicked 
     $("button.add").click(function() 
     { 
      // add new row to table using addTableRow function 
      addTableRow($("table")); 
      // prevent button redirecting to new page 
      return false; 

     }); 

     // function to add a new row to a table by cloning the last row and 
     // incrementing the name and id values by 1 to make them unique 
     function addTableRow(table) 
     { 

      // clone the last row in the table 
      var $tr = $(table).find("tbody tr:last").clone(); 


      // get the name attribute for the input and select fields 


      $tr.find("input,select,div").attr("name", function() 
      { 
       // break the field name and it's number into two parts 
       var parts = this.id.match(/(\D+)(\d+)$/); 
       // create a unique name for the new field by incrementing 
       // the number for the previous field by 1 
       return parts[1] + ++parts[2]; 

      // repeat for id attributes 
      }).attr("id", function(){ 
       var parts = this.id.match(/(\D+)(\d+)$/); 
       return parts[1] + ++parts[2]; 
      }); 
      // append the new row to the table 
      $(table).find("tbody tr:last").after($tr); 
      $tr.hide().fadeIn('slow'); 

      // row count 
      rowCount = 0; 
      $("#table tr td:first-child").text(function() { 
       return ++rowCount; 
      }); 

      // remove rows 
      $(".remove_button").on("click", function() { 
       $(this).parents("tr").fadeOut('slow', function() { 
        $(this).remove(); 
        rowCount = 0; 
        $("#table tr td:first-child").text(function() { 
         return ++rowCount; 
        }); 
       }); 
      }); 

     }; 
    }); 

OK,在该页面没有别的变化...

+0

添加了行,但仍然没有添加行。 – targsx 2013-03-18 14:39:23