开发者

Jquery displaying controls text on screen

This is the code in the script/head:

<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);

});

Code in the body:

    <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" />


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

val is a method, it should be...

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


If I'm reading your question correctly - I think you want the following...

Change:

$(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);
});

To:

$(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;
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜