【问题标题】:Dynamic input hidden field disappears动态输入隐藏字段消失
【发布时间】:2017-06-09 07:12:24
【问题描述】:

我一直在尝试将价格与整数相乘,并尝试将其保存在隐藏字段中,该字段将从隐藏字段中获取值,然后再次将其倍增,但第二次单击后隐藏字段消失,下面是我的代码。

function AddDeductPrice(x,y)
    {

        var z = $("#qty" + y).val();
        if (z > 0) {
            if (x == 0) {
                //i++;
                var l = document.getElementById('qty' + y).value;
                l++;
                $("#qty" + y).val(l);

                var j = document.getElementById('qty' + y).value;

                //var price = document.getElementById('PID' + y).value;
                var price = $("#PID" + y).val();
                alert(price);

                var MultiplyPrice = parseInt(j) * parseInt(price);

                alert(MultiplyPrice);

                $("#PID" + y).val(MultiplyPrice);
                //document.getElementById('PID' + y).value = MultiplyPrice;
                $("#priceID" + y).text(MultiplyPrice);

            }
            else {
                var y = $("#qty").val();
                if (z != 1) {
                    y--;
                    $("#qty").val(y);
                }
            }
        }
    }

这是javascript和Jquery,其他代码是下面的HTML

@if (Model.objlist1.Count > 0)
                {
                    int i = 0;
                    foreach (var item in Model.objlist1)
                    {
                        i++;
                        <tr>
                            <td><img src="~/imgProd/@item.image1" class="img-responsive img-rounded img-thumbnail"></td>
                            <td>
                                <h6>@item.product</h6>
                                <p>Gift options also available.</p>
                            </td>
                            <td><span>By @item.deliverydate</span></td>
                            <td>
                                <input type="text" name="qty" id="qty@(i)" maxlength="12" value="1" title="Qty" class="input-text qty form-control" disabled>
                                <div><p class="up" id="upid" onclick="AddDeductPrice(0, '@(i)');">+</p><p class="dn" id="dwnid" onclick="AddDeductPrice(1, '@(i)');">-</p></div>
                            </td>
                            <td id="priceID@(i)"><input type="text" value="@item.price" id="PID@(i)" style="visibility:hidden">₹ @item.price</td>
                            <td> <i class="fa fa-close span03"></i></td>
                            <td><a href=""><i class="fa fa-heart"></i> Move to Wishlist</a></td>
                        </tr>
                    }
                }

无论我是使用隐藏还是使用样式在第二次单击后隐藏输入,当我在 chrome 中使用 F12 时它会隐藏输入。 var price 在第二个显示 NaN 时为空,但在第一个显示值。

【问题讨论】:

  • 你能做个小提琴吗?

标签: jquery html arrays css


【解决方案1】:

这里的问题是在AddDeductPrice()$("#priceID" + y).text(MultiplyPrice); 行。

它将删除&lt;td id="priceID@(i)"&gt;&lt;/td&gt; 中的input

改为如下使用:

$("#priceID" + y).html($("#priceID" + y).html().replace($("#priceID" + y).text(), MultiplyPrice));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 2016-06-03
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多