Jquery加载不同的内容,并使用仍在运行的js操作加载的内容


Jquery loading different content, and manipulate the loaded content with the still running js

我有3个文件。1是php.index,2是javascript,3是php.loadinternet

php.index有一个小型

<div id="login-button" class = "knopf"><a href="?view=logs">Log in</a></div>

正在使用进行操作

$("#login-button").click(function(e){
        e.preventDefault();
        var input = $("#connectwindow, value").val();
    $.ajax({
        type: "GET",
        url: "ajax/loadinternet.php",
        data: {"targetip": input},
        success: function(data){
            //history.pushState({"internet.php?view=internetlog");
            $('#logoutput').html(data);

        },
        error: function(){
            alert ("error loading");
        }
    });

在将数据传递到loadinternet后,它会返回以下形式:

echo    '<div id="loginbox" align="right" class="boxgrid">
                    <form action="" method="post">Username: 
                    <input id="userlogin" type="text" class="textfieldcss" 
                    style="width: 60%;" name="username" value="'.$username.'"><br>
                    Password: &nbsp;<input id="userpassword"type="password" 
                    class="textfieldcss" style="width: 60%;" name="password" value="'.$username.'">
                    <input id="logintoip" type="submit" class="textfieldcss" style="text-align: right;" 
                    value="Log in">
                    </form>
                    </div>';

最后一个表单应该用这个表单处理:然而,它不起作用,我已经用了一个小时,试图把我的头裹在它周围。尝试了.click()和.submit()的预防,两者都不起作用。下面的点击函数中的简单警报也不起作用

$("#logintoip").click(function(e){
        e.preventDefault();
        var input = $("#userlogin, value").val();
        alert("stop");
        $.ajax(
        {
            type: "GET",
            url: "ajax/connect.php",
            data: {"targetip": input},
            success: function(index){
            $('#logoutput').html(index);
            },
            error: function(){alert("something went wrong here");}
            }       
        );
    });

加载页面时,#logintoip不存在,因此无法应用监听器。

试试这个方法:

$(document).on('click', '#logintoip', function(e){
    (...)
});