在jQuery对话框中删除重复的产品

时间:2013-11-15 05:18:43

标签: jquery

我在jquery对话框中遇到问题。它多次添加相同的项目我想只添加一个项目一次,但多次添加相同的项目。

我的代码:

 $("#dialog-form").dialog({
                    autoOpen: false,
                    height: 300,
                    width: 350,
                    modal: true,
                    buttons: {
                        "Submit": function() {
                            var bValid = true;
                            allFields.removeClass("ui-state-error");
                            bValid = bValid && checkLength(productname, "Product Name", 1, 100);
                            bValid = bValid && checkLength(qty, "Qty", 1, 4);
                            bValid = bValid && checkRegexp(qty, /^[+]?[0-9]*\.?[0-9]+$/, "Qty field allows only Positive numbers");
                            bValid = bValid && checkLength(price, "Price", 1, 4);
                            bValid = bValid && checkRegexp(price, /^[+]?[0-9]*\.?[0-9]+$/, "Price field allows Only Positive numbers");
                            //                            bValid = bValid && checkRegexp(amount, /^[+]?[0-9]*\.?[0-9]+$/, "Price field allows Only Positive numbers");
                            //                        alert("itemmmm mmmmmmmmm mmmmm " + itemid)

                            if (bValid) {
                                $("#users tbody").append("<tr id='" + ++rowIndex + "'>" +
                                    "<input type='hidden' value='" + itemid + "'  name='quotationDetails'>" +
                                    "<td><input id='med" + rowIndex + "' type='text' value='" + s + "'  name='quotationDetailsName' style='border: none;' readonly></td>" +
                                    "<td><input id='dos" + rowIndex + "' type='text' value='" + qty.val() + "' name='quotationDetailsQty' style='border: none;' readonly></td>" +
                                    "<td><input id='pric" + rowIndex + "' type='text' value='" + price.val() + "' name='quotationDetailsPrice' style='border: none;' readonly></td>" +
                                    "<td><input id='amoun" + rowIndex + "' type='text' value='" + qty.val() * price.val() + "' name='amonuttotal' style='border: none;' readonly></td>" +
                                    "<td><input type='button' id='" + rowIndex + "' value='Edit' onclick='editRow(this);'></td>" +
                                    "<td><input type='button'  productname='" + rowIndex + "' value='Delete' onclick='deleteRow(this);'/></td>" +
                                    "</tr>");                         
                                var n = document.getElementById("qty").value;
                                var p = document.getElementById("price").value;
                                var tmpTtl = document.getElementById("tamt").value;
                                var ttl = (parseInt(n) * parseInt(p)) + parseInt(tmpTtl);
                                document.getElementById("tamt").value = ttl;
                                $(this).dialog("close");

                            }
                        },
                        Cancel: function() {
                            $(this).dialog("close");
                        }
                    },
                    close: function() {
                        allFields.val("").removeClass("ui-state-error");
                    }
                });

                $("#create-user")
                .button()
                .click(function()
                {
                    ////alert(1);
                    $("#dialog-form").dialog("open");
                });
                $("#create-user1")
                .button()
                .click(function()
                {
                    $("#dialog-form").dialog("open");
                });

            });

我的DialogForm:

 <div id="dialog-form" title="">
                <p class="validateTips">All form fields are required.</p>
                <fieldset>
                    <label for="productname">Product Name</label>
                    <input type="hidden" id="itemid" value="<%= it.getItemId()%>" />

                    <!-- <input type="text"  id="productname"  class="text ui-widget-content ui-corner-all"/><p><span id="t"></span></p>-->
                    <select name="productname" id="productname" class="text ui-widget-content ui-corner-all" onchange="productnames(this);">

                        <option value="">Select Product</option>
                        <%
                            ItemDAO itDAO = new ItemDAO();
                            List lst = itDAO.getItems();
                            for (Iterator itm = lst.iterator(); itm.hasNext();) {
                                it = (Item) itm.next();
                        %>

                        <option value="<%= it.getItemId()%>"><%= it.getItemName()%></option>
                        <%
                            }
                        %>
                    </select>
                    <label for="qty">Qty</label>
                    <input type="text"  id="qty" class="text ui-widget-content ui-corner-all" />

                    <label for="price">Price</label>
                    <input type="text"  id="price"  class="text ui-widget-content ui-corner-all" />
                    <!--                    <label for="amount">Amount</label>
                                        <input type="text"  id="amount" class="text ui-widget-content ui-all" />-->


                </fieldset>
            </div>        

1 个答案:

答案 0 :(得分:0)

尝试写作

            $("#create-user").click(function()
            {
                $("#dialog-form").dialog("open");
            });

并且您可以指定多次生成哪个项目