Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jquery中获取按钮控件?_Jquery_Html_Jquery Mobile - Fatal编程技术网

如何在jquery中获取按钮控件?

如何在jquery中获取按钮控件?,jquery,html,jquery-mobile,Jquery,Html,Jquery Mobile,我有2个HTML文件 在First.html中,我想包括Second.html。当我点击登录按钮时,我无法从js文件中获取数据或控件 First.html <!DOCTYPE html> <html> <head> <title>Insert title here</title> <script type="text/javascript" src='js/jquery.js'><

我有2个HTML文件

在First.html中,我想包括Second.html。当我点击登录按钮时,我无法从js文件中获取数据或控件

First.html

<!DOCTYPE html>
<html>
  <head>      
    <title>Insert title here</title>    
    <script type="text/javascript" src='js/jquery.js'></script>        
    <script type="text/javascript" src="js/first.js"></script>
</head>
<body>  
     <div id="content"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>  
    <script type="text/javascript" src='js/jquery.js'></script>
</head>     
<body>      
<div>
    <div data-role="fieldcontain">
        <label id="luserid" ><strong>UserId : </strong></label>
        <input type="text" name="userid" id="userid" value="" class="logon" placeholder="Username" required/>
    </div>
    <div data-role="fieldcontain">
        <label id="lpassword"><strong>Password :</strong></label>
        <input type="password" name="password" id="password" class="logon" value="" placeholder="Password" required/>
    </div>
    <div class="ui-body">
        <fieldset class="ui-grid-a">                            
                <div class="ui-block-a"><a data-role="button" id="loginbtn" data-theme="b">Login</a></div>                          
        </fieldset>
    </div>              
</div>
</body>
</html>

请帮我解决这个问题。…

您应该在
加载
回调中附加
单击
处理程序:

$(document).ready(function(){   
  $('#content').load('login.html', function() {
     $("#loginbtn").click(function () {
      alert("Inside Login");
     });        
  }
});  
代码失败的原因是,当您尝试设置
单击处理程序时,
#loginbtn
元素可能还不存在

$(document).ready(function(){   
  $('#content').load('login.html', function() {
     $("#loginbtn").click(function () {
      alert("Inside Login");
     });        
  }
});