简体   繁体   English

在动态添加的行上链接选择

[英]Chained Select on Dynamically added row

I found this from previous Question, The Answer is Working OK on Two Select List. 我从上一个问题“两个选择列表中的答案正常”中发现了这个问题。
But if i need to Add Third Select even when its not Associated from the First And Second Select, 但是,即使我没有从“第一选择”和“第二选择”关联的情况下,即使我需要添加“第三选择”,
The Chained Select Function Will Not Work. 链接选择功能将不起作用。
I Want to Add a Third Select which is not associated from the Two Select. 我想添加一个与“两个选择”无关的“第三选择”。

Here is the Content of the Previous Question 这是上一个问题的内容

<table id="tableID" border="1">
<tbody>
<tr>
  <td> <a href="#" onClick="addRow(tableID)">Add</a>
  </td>
  <td>
    <select id="mark" name="mark">
    <option value="bmw">BMW</option>
    <option value="audi">Audi</option>
    </select>
  </td>
  <td>
    <select id="series" name="series">
    <option value="series-3" class="bmw">3 series</option>
    <option value="series-5" class="bmw">5 series</option>
    <option value="series-6" class="bmw">6 series</option>
    <option value="a3" class="audi">A3</option>
    <option value="a4" class="audi">A4</option>
    <option value="a5" class="audi">A5</option>
    </select>
  </td>
 </tr>
</tbody>

 var row = $('#tableID tbody:first').html();
$("#series").chained("#mark");

function addRow(tableID) {
 $(row).appendTo('#tableID');
 var rowCnt = $('#tableID tbody>tr').length;

 $('#tableID tbody>tr:last select:first').attr('id', 'mark' + rowCnt);
 $('#tableID tbody>tr:last select:last').attr('id', 'series' + rowCnt);

Here is The Link: 链接在这里:

http://jsfiddle.net/f433g/ http://jsfiddle.net/f433g/

Kindly help me with this Guys, Thanks 请帮我这个家伙,谢谢

The problem was from the select:last selector, the new #series selects weren't getting the rowCnt added to their ID. 问题出在select:last选择器中,新的#series选择没有将rowCnt添加到其ID中。

as you know the id of the select you can use that for the selector instead. 如您所知,选择的ID可以将其用于选择器。

$('#tableID tbody>tr:last #mark').attr('id', 'mark' + rowCnt);
$('#tableID tbody>tr:last #series').attr('id', 'series' + rowCnt);

http://jsfiddle.net/2KBsw/ http://jsfiddle.net/2KBsw/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM