0

我想在jquery中增加隐藏字段值,但是当我在将值初始化为隐藏字段之前打印值时它不会增加只是打印“2”我的代码是,

<script type="text/javascript">
    var k=0,j=0;
        $(document).ready(function () {
            $("#btnAdd").click(function () {
                var field = $("#field").val();
                 var DDL_fromProfession="<select name='ParametersFromProf' id='DDL_FromProYear'>";
                 for(var i=1950;i<2012;i++)
                 {
                 DDL_fromProfession +="<option text='"+i+"' value='"+i+"'>"+i+"</option>";
                 }
                 DDL_fromProfession +="</select>";
                var DDL_ToProfession="<select name='ParametersToProf'  id='DDL_ToProYear'>";
                for(var i=1950;i<2012;i++)
                 {
                 DDL_ToProfession +="<option text='"+i+"' value='"+i+"'>"+i+"</option>";
                 }
                 DDL_ToProfession +="</select>";
             k+=1;
                var newRow1="<tr><td align='center' style='font-size: large; color: #212121;' height='35px'>from"
                +DDL_fromProfession +" to "+DDL_ToProfession +"</td></tr>"
                +"<tr><td align='center' style='font-size:large;color:#212121;' height'35px'>"
                +"<input type='checkbox' name='chkbx_CurrPro"+k+"' value='Yes'>I currently work here</input>"
                +"<input type='hidden' id='hide' name='hidden' value='"+k+"'></input>";
               // alert(document.getElementByName("valPro").value);
                //alert($('input').attr('hidden'));
                //alert($('input#hide').val());

                var input = "<input name='parameters' id='field' type='text' />";
                var input1="<input name='parametersCompany' id='field' type='text'/>"
                var newRow = "<tr><td align='center' style='font-size: x-large; color: #212121;' height='35px'>" 
                + input + " at " +input1 +"</td></tr>";
                $('#controls').append(newRow);
                $('#controls').append(newRow1);
                var value = parseInt($(":hidden[name='hidden']").val()) + 1;
                alert(value);
            });
        });
    </script>

隐藏领域:

   +"<input type='hidden' id='hide' name='hidden' value='"+k+"'></input>";

印刷价值:

 var value = parseInt($(":hidden[name='hidden']").val()) + 1;
                alert(value);

希望你的建议

4

1 回答 1

1

我想你想要隐藏值(:hidden[name='hidden'])= 2(value写在alert)?

然后你必须在var value = parseInt($(":hidden[name='hidden']").val()) + 1;=>之后写一行$(":hidden[name='hidden']").val(value);

在这种情况下,您的隐藏值是1您可以测试的alert(parseInt($(":hidden[name='hidden']").val()))

于 2013-01-30T08:22:57.433 回答