<script type="text/html" id="addPlace"> <tr> <th>营业场所大类</th> <td> <select class="bigPlaceSelect" style="width:100%;"> </select> </td> <th>营业场所小类</th> <td> <select class="smallPlaceSelect" style="width: 90%;"> <option value="">请选择</option> </select> <input type="button" onclick="deletePlace(this)" id="delectPlacebtn" style="padding:2px 4px;" value="删除" /> </td> </tr> </script> <script type="text/html" id="addTD"> <tr> <th>检查标准大类</th> <td> <select class="bigClaseSelect" style="width: 100%;"> </select> </td> <th>检查标准小类</th> <td> <select class="smallClassSelect" style="width: 90%;"> <option value="">请选择</option> </select> <input type="button" onclick="deleteClass(this)" id="deleteClassbtn" style="padding: 2px 4px;" value="删除" /> </td> </tr> </script> <script> $("#addPlacebtn").click(function () { var html = template('addPlace', { list: [] }); var big = $("#SOTYPEBID").html(); var dom = $(html); dom.find(".bigPlaceSelect").html(big); dom.find(".bigPlaceSelect").change(function () { var BID = $(this).val(); $.get("/BJGL/GetBOTYPE", { PID: BID }, function (data) { var str = "<option value=''>请选择</option>"; $.each(data, function (i, item) { str += "<option value='" + item.Value + "'>" + item.Text + "</option>"; }); dom.find(".smallPlaceSelect").html(str); }); dom.find(".smallPlaceSelect").change(function () { var SID = $(this).val(); }); }); $("#addNewPlace").before(dom); }); function deletePlace(s) { $(s).parent().parent().remove(); }; function test1() { var trList = $("#new").children("tr") for (var i = 0; i < trList.length; i++) { var tdArr = trList.eq(i).find("td"); var history_income_type = tdArr.eq(0).find("select").val(); var history_income_typ = tdArr.eq(1).find("select").val(); alert(history_income_type); alert(history_income_typ); } } </script> <script> $("#addClassbtn").click(function () { var html = template("addTD", { list: [] }); var bigSelect = $("#BJLAWTYPEBID").html(); var dom = $(html); dom.find(".bigClaseSelect").html(bigSelect); //获取检查小类 dom.find(".bigClaseSelect").change(function () { var PID = $(this).val(); $.get("/BJGL/GetBJLAWTYPE", { PID: PID }, function (data) { var str = "<option value=''>请选择</option>"; $.each(data, function (i, item) { str += "<option value='" + item.Value + "'>" + item.Text + "</option>"; }); dom.find(".smallClassSelect").html(str); }); }); $("#addNewClass").before(dom); }); function test() { var obj = {}; var st = "2" + "," + "3"; if (st in obj) { } else { obj[st] = 0; } } function deleteClass(e) { $(e).parent().parent().remove(); } </script>
我是这样添加动态tr的,因为要显示多行营业大类跟营业小类,所以动态添加了tr,我想把这几个tr中的数互相比较下,如果相同就隐藏,请问各位大神怎么把这些数全部取出来啊,我试了下这个方法不行,代码如下
function test1() { var trList = $("#new").children("tr") for (var i = 0; i < trList.length; i++) { var tdArr = trList.eq(i).find("td"); var history_income_type = tdArr.eq(0).find("select").val(); var history_income_typ = tdArr.eq(1).find("select").val(); alert(history_income_type); alert(history_income_typ); }
)
我想把tbody写入原来的那个营业大类的tr前面,可是那样的话就获取不到值了,如果写到动态tr之前,页面就变了
...你的代码看起来太糟糕啦,没法给你看。根据你的描述,我有个办法不知道能不能帮到你。
既然你能动态的添加tr,那你为什么不能再动态添加的同时,动态创建数组保存你最终想取到的值。这样一来你就不用在生成过后再去取值啦。不知道能不能帮到你~
建议你修改下问题,把代码格式化一下。
谢谢你哦,我改下格式
@forech