0

私は自分のページにポップアップボックスを作成しようとしています.userNameを尋ね、そのユーザーに警告します..ここに私のhtmlコードがあります..

<a class="pop-up-link" href="#" title="View Pop Up" onClick="popUp()">Click Here</a>

    <div class='popup'> <a href='#' title="Close" class='close'><img src='close.png' alt='close' height="20" width="20" /></a>
        <div class="pop-heading">
            <h3>Pop Up</h3>
        </div>
        <div class="pop-info">
        </div>
    </div>

そして、私は次のようなjqueryコードを持っています

function popUp()
{
    var htmlString = "";
    var height = $(document).height();
    var width = $(document).width();
    var spanHeight = $('.popup').height();
    var spanWidth = 500;

    $('.pop-up-link').click(function() { 
        $(this).next()
            .css({ "top" :  height/2 - spanHeight/2 })
            .css({ "left" : width/2 - spanWidth/2 })
            .fadeIn(100);
    });

    $(".close").click(function () {
        $('.pop-up-link').next().fadeOut(100);
    });

    htmlString+='<input type="text" id="User" name="User"/>';
    htmlString+='<input type="button" value="Login" onclick="userLogin()">';
    $(".pop-info").html(htmlString);
}

function userLogin()
{
 alert($('#User').val());
}

しかし、アラート ボックスには値がありません。$('#User').val('hello');次に、userLogin関数のように、(その動作を確認するために)値を入れようとしました。しかし、それも機能していません。入力フィールドにアクセスできないと思います..そのテキストボックスの値を取得する方法を誰か説明できますUserか?

4

1 に答える 1

1
于 2012-09-20T10:08:33.567 に答える