如何在jquery中获取按钮控件?
我有2个HTML文件 在First.html中,我想包括Second.html。当我点击登录按钮时,我无法从js文件中获取数据或控件 First.html如何在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'><
<!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");
});
}
});