简体   繁体   中英

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. 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. You can see in the update function a text box is appended to the #hidden element. 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. 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. Does anyone have idea what's going on?

EDIT: the '#hidden' element is the same thing as '#asdf' full code:

<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. The ViewState element is probably the first one on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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