我正在运行此代码,一旦文档准备好,就会调用脚本方法。此外,如果我放置一个调试器并警告它的值,我可以获得该对象,但它会
"Uncaught TypeError: Cannot read property 'ecommerce' of undefined"
在本地运行时抛出一个错误。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var jsonObj = {
"input": {
"ecommerce":
{
"id": 123,
"name": "isEcommerce",
"type": "boolean",
"actionType" : "radioButton",
"child": {"yes":["p","q","e","w"],
"no":["a","b","c","d"]}
},
"bad website":
{
"id": 2324,
"name": "isBadWebsite",
"type": "boolean",
"actionType" : "radioButton",
"child": {"yes":["erw","sd","sd","sd"],
"no":["sd","sd","sd","fd"]}
}
}
};
var data = jsonObj;
$(document).ready(function(data){
alert("HI!!");
alert(data);
alert(data.input);
alert(data.input.ecommerce);
});
function tackleEvent(obj){
alert("Clicked " + obj);
}
</script>
</head>
<title>Hello!</title>
<body>
</body>
</html>
错误跟踪:
Uncaught TypeError: Cannot read property 'ecommerce' of undefined ui:34
(anonymous function) ui:34
f.Callbacks.n jquery.min.js:2
f.Callbacks.o.fireWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.B jquery.min.js:2
为什么它无法获取对象并且在键入相同内容时正在工作?