当我点击'AjaxButton'通过ajax的方式请求页面'ajax.jsp'时'html'的值是'ajax.jsp'的代码,但是当我将它附加到div'#ajaxHtml'时,丢失了,alert('window msg'); 未执行,单击“methodOne”按钮也未执行;
$(function(){
alert('jquery init method!');
});
上面的代码也没有执行!
为什么 ?我该如何解决这个问题,或者是另一种实现相同的方法?
main.jsp
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>Ajax</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/mobile/mobile/common/script/jQuery/jquery.mobile-1.0a2.css" />
<script type="text/javascript" src="/mobile/mobile/common/script/jQuery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="/mobile/mobile/common/script/jQuery/jquery.mobile-1.0a2.js"></script>
<script>
$(function(){
$('#ajax').click(function(){
ajaxTo();
});
});
function ajaxTo(){
$.ajax({
url: '${ctxPath}/cf/customFormTemplateAction!context.action',//ajax.jsp
type: 'POST',
data: {fileName:'ajax'},
success: function( html ) {
$('#ajaxHtml').append(html);
}
});
}
</script>
</head>
<body style="background-Color:red;">
<div id="zhaosheng" style="border:10px solid lightblue;">
<div id="page" data-role="page" style="border:2px solid blue;" data-theme='d' data-zhaosheng='zhaosheng'>
<div data-role="header" data-position="inline" data-position="fixed">
<h1>Chinese</h1>
</div>
<div data-role="content">
<a id="ajax" data-role="button" rel="external">AjaxButton</a>
<div id="ajaxHtml"></div>
</div>
<div data-role="footer" data-position="fixed">
<h1>DCL[zhaosheng.wolf@163.com]</h1>
</div>
</div>
</div>
</body>
</html>
ajax.jsp
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>China</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/mobile/mobile/common/script/jQuery/jquery.mobile-1.0a2.css" />
<script type="text/javascript" src="/mobile/mobile/common/script/jQuery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="/mobile/mobile/common/script/jQuery/jquery.mobile-1.0a2.js"></script>
<script defer="defer">
function methodOne(){
alert('This is a test message!');
}
$(function(){
alert('jquery init method!');
});
alert('window msg');
</script>
</head>
<body >
CONTENT<br/>
<a href='javascript:methodOne();'>methodOne</a>
</body>
</html>