简体   繁体   English

jQuery获取ASP.net隐藏文本框值的值

[英]jQuery getting value of ASP.net hidden textbox value

This problem is a little bizarre and I'm curious if anyone has any idea what's going on. 这个问题有点奇怪,我很好奇是否有人知道发生了什么。 You can get the CSS,HTMl and JS here , but the behavior I see on my local machine isn't the same as in the fiddle. 你可以在这里获得CSS,HTMl和JS,但我在本地机器上看到的行为与小提琴中的行为不同。 The intent is was that a user will click on a span tag inside of a div and and a modal will pop up (which I haven't gotten to yet) and the user will be able to edit and save changes. 目的是用户将点击div内部的span标签,并弹出一个模态(我还没有得到),用户将能够编辑和保存更改。 You can see in the update function a text box is appended to the #hidden element. 您可以在更新功能中看到一个文本框附加到#hidden元素。 Although I never set the value of the text box, when a span tag is clicked a text box is appended to the element with (almost) the entire value of the view state hidden ASP.net field. 虽然我从未设置文本框的值,但是当单击span标记时,文本框将附加到元素上(几乎)视图状态隐藏的ASP.net字段的整个值。 I changed the id of the hidden element to garbage thinking maybe hidden was a bad ID to use, but I still got the same effect. 我将隐藏元素的id更改为垃圾思想,可能隐藏的是一个坏ID,但我仍然有同样的效果。 Does anyone have idea what's going on? 有谁知道发生了什么?

EDIT: the '#hidden' element is the same thing as '#asdf' full code: 编辑:'#hidden'元素与'#asdf'完整代码相同:

<script type="text/javascript">
        $(document).ready(function () {
            var personArray = [{
                name: 'firstName',
                gender: 'male',
                age: 30
            }, {
                name: 'secondName',
                gender: 'female',
                age: 20
            }];

            //finds over object in the array and every property on that object
            //and makes a control out of it and styles is.
            function pretty(array) {
                var divArray = [];
                for (var i = 0; i < array.length; i++) {
                    var $div = $('<div>').addClass('person');
                    for (var prop in array[i]) {
                        var $span = $('<span>').text(prop + ': ' + array[i][prop]);
                        $div.append($span);
                    }
                    divArray.push($div);
                }
                return divArray;
            }

            $('body').append(pretty(personArray));

            $('.person span').click(function () {

                update($(this).parent());
            });
            function update(control) {
                var $spans = $(control).children('span');
                for (var i = 0; i < $spans.length; i++) {
                    $('#asdf').append($spans[i]).css('float', 'left');
                    var textBox = $('input').attr('type', 'textbox').css('float', 'right');
                    $('#asdf').append(textBox);
                }
                $('.updatePanel').fadeIn();
            }
            console.log('wEPDwUKLTIwNjAyODU4M2RkOhAAaDmHX8rBCXDQytiqIx94ch'.length);
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="asdf" style="float:right" class="updatePanel"></div>
    </div>



    </form>
</body>

On this line 在这条线上

var textBox = $('input').attr('type', 'textbox').css('float', 'right');

You probably want to do: 你可能想做:

var textBox = $('<input>').attr('type', 'textbox').css('float', 'right');

ViewState is stored in a hidden input element, and doing $("input") will select all input elements on the page. ViewState存储在隐藏的输入元素中,执行$(“input”)将选择页面上的所有输入元素。 The ViewState element is probably the first one on the page. ViewState元素可能是页面上的第一个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM