2013-06-21 47 views
0

开始:我对前端开发非常新(它被添加到我的java后端工作:))。我有一个模式,打开页面上有两行的表 - 每个有2个输入和一个选择框。如果你点击一个按钮....它应该添加具有相同元素的另一行。他们使用这样做:有一个隐藏着元素的表格页脚(从行开始:<tr>),然后当您单击该按钮时,它会调用表格主体和.append页脚。然后调用三个元素的attr并更改id和名称。由于某种原因,如果页脚未被隐藏......下拉菜单可以正常工作,但复制版本不会。我们调查了名称,值等。这些值在呈现的html中...下拉菜单没有打开。不能追加选择框与JQuery

所以,现在我正在努力做的......我觉得可能会更干净。用html创建一个变量...并在每次单击按钮时追加。但是select元素有一个标签被写入...所以我不知道这是否是问题,但是每次我尝试将它添加到混合中......有关于意外标记的错误(<)。如果我采取一条线开始< dfm:catombobox >远 - 它的作品...任何人有想法来帮助我添加“catombobox”这是选择与标签? PS:如果我把报价拿走,只是将该行复制到原始表格中......它可以工作?

var newRow = '<tr>'+ 
       '<td nowrap="nowrap"><strong>R</strong> <input class="amount input-small" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>'+ 
       '<td nowrap="nowrap" style="padding-top: 7px;">'+ 

       '<dfm:catombobox cssClass="input-medium" id="CategoryId_Test" name="CategoryName_Test" showEmptyCategory="true" showGroups="true" value=""/>'+ 

       '</td>'+ 
       '<td><input class="input-medium" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>'+ 
       '<td><a class="remove" href="#"><i class="icon-remove"></i></a></td>'+ 
       '</tr>'; 
      $("#mytable tbody").append(newRow); 

回答

0

尝试使用select代替DFM的:catombobox

+0

感谢。不幸的是,选择框中的数据有点复杂。它来自不同的层面,标签不仅在设计时考虑到了公司的造型标准,而且还考虑到将正确的选项和组合放在下面。我测试了我的html中的确切代码行,它的工作原理。所以看起来问题是如何让变量或“apped”认识到这应该像hmtl页面一样处理? – user990855

+0

然后在这种情况下只需使用:$(“#mytable tbody”)。append(newRow);通过将它绑定到按钮单击事件 –

0

这里检查其做工精细

adding new rows to table

var newRow = '<tr>' + 
    '<td nowrap="nowrap"><strong>R</strong> <input class="amount input-small" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>' + 
    '<td nowrap="nowrap" style="padding-top: 7px;">' + 

    '<dfm:catombobox cssClass="input-medium" id="CategoryId_Test" name="CategoryName_Test" showEmptyCategory="true" showGroups="true" value=""/>' + 

    '</td>' + 
    '<td><input class="input-medium" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>' + 
    '<td><a class="remove" href="#"><i class="icon-remove"></i></a></td>' + 
    '</tr>'; 
$("#btn").on('click',function(){ 
    $("#mytable tbody").append(newRow); 
}) 
+0

因此,目前变量声明以及append在click函数中:$(“#add”)。click(function(){......})。我应该有变量全球然后只附加在这个功能?这有什么不同吗? – user990855

+0

好的 - 我现在只能打开你的例子。如果你看我的表格行......有三列。第1列和第3列有输入。第2列是下拉菜单。你的例子也没有显示选择框? – user990855

+0

http://jsfiddle.net/Faheem66/XMBZk/3/ – FLF