Uncaught TypeError: Cannot read property 'createChild' of undefined

错误为:Uncaught TypeError: Cannot read property 'createChild' of undefined
一、原因分析:
   没有把js代码放到Ext.onReady函数中,深层次的原因还没搞明白。。。

二、错误错码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=gbk">
	<title>表单与输入控件</title>
	<link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css" />
    <script type="text/javascript" src="../ext-all.js"></script>
    <script type="text/javascript" src="Chinese.js"></script>
    <script type="text/javascript">
    	var form = new Ext.form.FormPanel({
			title : 'form',
			defaultType : 'textfield',
			buttonAlign : 'center',
			frame : true,
			width : 220,
			fieldDefaults : {
				labelAlign : 'right',
				labelWidth : 70
			},
			items : [{
				fieldLabel : '文本框'
			}],
			buttons : [{
				text : '按钮'
			}]
		});

	form.render("form");
    </script>
	</head>
	<body>
	       <div id="form"></div>
	</body>
</html>


三、修正后代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=gbk">
	<title>表单与输入控件</title>
	<link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css" />
    <script type="text/javascript" src="../ext-all.js"></script>
    <script type="text/javascript" src="Chinese.js"></script>
    <script type="text/javascript">
    	Ext.onReady(function() {
			var form = new Ext.form.FormPanel({
				title : 'form',
				defaultType : 'textfield',
				buttonAlign : 'center',
				frame : true,
				width : 220,
				fieldDefaults : {
					labelAlign : 'right',
					labelWidth : 70
				},
				items : [{
					fieldLabel : '文本框'
				}],
				buttons : [{
					text : '按钮'
				}]
			});

			form.render("form");
		})

	form.render("form");
    </script>
	</head>
	<body>
	       <div id="form"></div>
	</body>
</html>

猜你喜欢

转载自hqzmss.iteye.com/blog/2362181