日期:2014-05-16  浏览次数:20515 次

json+jquery显示加载内容出不来
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="/js/json.js"></script>
</head>
<body>
<div id="msg"></div>
</body>
</html>

$(document).ready(
function(){
var user = {"name":"张三","age":14,"wife":null};
alert($("#msg"));
$("#msg").append("姓名:"+user.name+"<br>").
append("年龄:"+user.age+"<br>").
append("配偶:"+user.wife);
});


------解决方案--------------------
如下代码,是可以的啊

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<div id="msg"></div>
<script type="text/javascript">
$(document).ready(
    function(){
        var user = {"name":"张三","age":14,"wife":null};
        alert($("#msg"));
        $("#msg").append("姓名:"+user.name+"<br>").
        append("年龄:"+user.age+"<br>").
        append("配偶:"+user.wife);
});
</script>
</body>
</html>

------解决方案--------------------