Jquery在屏幕上显示控件文本

时间:2011-07-19 16:52:27

标签: jquery asp.net ajax

这是脚本/头部中的代码:

<script type="text/javascript">

$(function () {


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



        var theButton = $(this);

        $('#disclaimer').slideToggle('slow', function () {
            theButton.val($(this).is(':visible') ? 'Hide' : 'Show');
        });




        return false;
    });
    $('<h2></h2>').html($('#MessageText').val);

});

正文中的代码:

    <p  id="disclaimer"  > 

    <input id="MessageText" type="text" /> //I this value to appear in an inserted h2 tag after the button toggles the <p>


</p>

<asp:Button ID="Button21" CssClass="HideButton" runat="server" Text="Hide" />

2 个答案:

答案 0 :(得分:2)

$('<h2></h2>').html($('#MessageText').val);

值是一种方法,它应该是......

$('<h2></h2>').html($('#MessageText').val());

答案 1 :(得分:1)

如果我正确地阅读你的问题 - 我想你想要以下......

变化:

$(function () {
    $('.HideButton').click(function () {
        var theButton = $(this);

        $('#disclaimer').slideToggle('slow', function () {
            theButton.val($(this).is(':visible') ? 'Hide' : 'Show');
        });

        return false;
    });
    $('<h2></h2>').html($('#MessageText').val);
});

要:

$(function () {
    $('.HideButton').click(function () {
        var theButton = $(this);

        $('#disclaimer').slideToggle('slow', function () {
            theButton.val($(this).is(':visible') ? 'Hide' : 'Show');
        });
        theButton.after($('<h2></h2>').html($('#MessageText').val()));

        return false;
    });
});