无法使用Jquery在第二次向Textbox显示值

时间:2014-03-13 09:04:18

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

我正在开发MVC应用程序。

我已经显示了确认模式框。

它只能一次正常工作....如果我再次打开它根本不起作用...... 检查下图....

当我将条目放在调度文本框(34)中时,在模糊事件上,它会将光束大小值(60)相乘并显示在双鱼座文本框(2040)中。工作正常,

enter image description here

当我关闭该框并再次打开它并将值再次放入发送文本框时,它根本不起作用...

enter image description here

这是我的代码......

<h2 style="font-size:22px;">Dispatch </h2>


<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 @using (Html.BeginForm("Create", "Dispatch", FormMethod.Post, new { enctype = "multipart/form-data", id = "frmCreate" }))

{
        @Html.ValidationSummary(true)   


  <div class="row-fluid">        

       <div class="span12 roundedDiv" >

           <div class="span12" style="margin-left:0px; margin-bottom:10px;">
          <legend style="color:#ee8929; font-size:16px;">Primary Information</legend>

        </div>



           <div class="span12" style="margin-left:0px; margin-bottom:10px;">
          <legend style="color:#ee8929; font-size:16px;">Product List</legend>

      <div class="row-fluid">   
           <table class="table table-striped table-hover" id="mytable">
               <thead>
    <tr >
        <th>
          Section Name
        </th>
         <th>
          Section Code
        </th>

    </tr>
</thead>

<tbody id="tbody">


@foreach (var item in ViewBag.ProductList)

{
    <tr id="tableRow" >
        <td  >
            @item.SectionName
        </td>

            <td >
            @item.SectionCode
        </td>

         <td  id="editRow" >

          <a href="#" class="editClass"  style="font-size: 12px; text-decoration: none; margin-right: 10px;">Edit </a>        

         </td>

    </tr>
}

</tbody>

</table>

</div>

 </div>
    <div class="span11" >              
        <div class="span3"> Order Date : @System.DateTime.Now.ToShortDateString()</div>
            <div class="span9" style="text-align:right">
                <button   type="button" class="btn btn-primary" id="btnDispatch" >Dispatch</button>
                <input class="btn btn-default" value="Back" style="width:40px;" onclick="window.location.href='@Url.Action("index")    '"/>
            </div>
        </div>
    </div>
  </div>
} 





<script type="text/javascript">
    $(document).ready(function () {

        $('.editClass').click(function () {


            $('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="btnClose1"> × </button><h5 id="dataConfirmLabel">Edit </h5> </div><div class="modal-body" ><html><table style="width:530px"><tr> <th style="width:120px">Bundle Size</th><th>Count</th><th>Dispatch</th> <th> Pieces</th> </tr><tr> <td><div id="bundleSize1" >60 </div></td> <td><div  id="count1">3</div></td>  <td><input  id="dispatchValue1" type="text"  style="width:100px ;height:15px ;margin:1px" /></td> <td> <input  id="pieces1"  type="text"  style="width:100px ;height:15px ;margin:1px" disabled/></td> </tr> <tr> <td><div id="bundleSize2" >10</div></td> <td><div  id="count2">8</div></td><td><input id="dispatchValue2" type="text" style="width:100px ;height:15px ;margin:1px" /></td><td> <input   id="pieces2"  type="text"  style="width:100px ;height:15px ;margin:1px" disabled/></td> </tr> <tr style="border-bottom:solid #e8eef4 thick;"> <td><div id="bundleSize3" >1</div></td><td><div  id="count3">20</div></td><td><input id="dispatchValue3" type="text" style="width:100px ;height:15px ;margin:1px" /></td><td> <input    id="pieces3" class="txt" type="text"  style="width:100px ;height:15px ;margin:1px" disabled/></td>  </tr> <tr> <td colspan="3" style ="text-align: right; border-right:solid white;"> Total</td> <td> <input  id="total" type="text" value="0"  style="width:100px ;height:15px ;margin:1px"  disabled /></td></tr></table> </html></div> <div class="modal-footer"><button type="button" id="btnOk1"  class="btn btn-primary" data-dismiss="modal" aria-hidden="true" >OK</button> <button type="button" id="btnCancel1"  class="btn btn-default" data-dismiss="modal" aria-hidden="true" >Cancel</button> </div></div> ');

            $('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm'));
            $('#dataConfirmModal').modal({ show: true }); 

        });

        $('body').on('click', '#btnOk1', function() {


        });

        $('body').on('click', '#btnCancel1', function() {

            var url="@Url.Action("DispatchNow")";
            $(location).attr('href', url);
        });

        $('body').on('click', '#btnClose1', function() {

            var url="@Url.Action("DispatchNow")";
            $(location).attr('href', url);
        });
  

下面是文本框的模糊事件,进行计算。计算没问题......但是值没有分配给Pieces文本框。

        $('body').on('blur', '#dispatchValue1', function() {

            var dispatchValue = $('#dispatchValue1').val();
            var bundleSize = $('#bundleSize1').text();
            var nPieces1 = dispatchValue*bundleSize;
            $('#pieces1').val(nPieces1);

            var ntotal= $('#total').text();



            $('#supplyQuantity').val(sum);
            if(ntotal > 0)
            {

                var ntotal = $('#total').val();
                var sum = parseFloat(ntotal) +parseFloat(nPieces1);
                $('#pieces1').val(sum);
                $('#total').val(sum);
                $('#supplyQuantity').val(sum);
            }
            else
            {

                var sum = parseFloat(nPieces1);
                $('#pieces1').val(sum);
                $('#total').val(sum);
                $('#supplyQuantity').val(sum);
            }



        });







    });


    $(document).ready(function () {

        $('#btnDispatch').click(function () {

            $('body').append('<div id="dataConfirmModal1" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="btnClose"> × </button> <h5 id="dataConfirmLabel">Dispatch Alert</h5> </div><div class="modal-body"><h5>This order is dispatched.</h5><br/></div><div class="modal-footer"><button type="button" id="btnOk"  class="btn btn-primary" data-dismiss="modal" aria-hidden="true" >OK</button> </div></div> <div class="modal-backdrop"></div>');
            $('#dataConfirmModal1').find('.modal-body').text($(this).attr('data-confirm'));
            $('#dataConfirmModal1').modal({ show: true }); 

        });

        $('body').on('click', '#btnOk', function() {


            var url="@Url.Action("index")";
            $(location).attr('href', url);
        });

        $('body').on('click', '#btnClose', function() {

            var url="@Url.Action("index")";
            $(location).attr('href', url);
        });

    });


    </script>

1 个答案:

答案 0 :(得分:0)

您能否在此代码块中呼叫提醒;

$('body').on('blur', '#dispatchValue1', function() {
        var dispatchValue = $('#dispatchValue1').val();
        alert(dispatchValue );
        var bundleSize = $('#bundleSize1').text();
        alert(bundleSize);
        var nPieces1 = dispatchValue*bundleSize;
        $('#pieces1').val(nPieces1);

我认为第二次其中一个警报值为null或为空。请检查一下。你失去了那个领域的控制权。