繁体   English   中英

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

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

这个问题有点奇怪,我很好奇是否有人知道发生了什么。 你可以在这里获得CSS,HTMl和JS,但我在本地机器上看到的行为与小提琴中的行为不同。 目的是用户将点击div内部的span标签,并弹出一个模态(我还没有得到),用户将能够编辑和保存更改。 您可以在更新功能中看到一个文本框附加到#hidden元素。 虽然我从未设置文本框的值,但是当单击span标记时,文本框将附加到元素上(几乎)视图状态隐藏的ASP.net字段的整个值。 我将隐藏元素的id更改为垃圾思想,可能隐藏的是一个坏ID,但我仍然有同样的效果。 有谁知道发生了什么?

编辑:'#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>

在这条线上

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

你可能想做:

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

ViewState存储在隐藏的输入元素中,执行$(“input”)将选择页面上的所有输入元素。 ViewState元素可能是页面上的第一个元素。

暂无
暂无

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

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