小弟想用Ext做一个用户登录界面:代码如下,已经做好,关键是窗口总是在左上角,应该怎样放到窗口的中间位置:
<script type="text/javascript">
Ext.onReady(function() { Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var bd = Ext.getBody();
bd.createChild({ tag: 'h2', html: '' }); var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
frame: true,
title: 'Login Window',
bodyStyle: 'padding:5px 5px 0',
width: 350,
x: 400,
y: 300,
renderTo: bd,
defaults: { width: 230 },
defaultType: 'textfield', items: [{
id: 'userid',
fieldLabel: 'UserId',
name: 'first'
}, {
id: 'pass',
fieldLabel: 'Password',
name: 'last'
}
], buttons: [{
text: 'Login',
handler: function() {
var user_id = Ext.getDom('userid').value;
var pass = Ext.getDom('pass').value;
Ext.Ajax.request({
url: "Login.ashx",
method: "post",
params: { userid: user_id, password: pass },
success: function() { window.open("index.aspx"); }
});
}
}]
});
simple.render(document.body);
});
</script>
<script type="text/javascript">
Ext.onReady(function() { Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var bd = Ext.getBody();
bd.createChild({ tag: 'h2', html: '' }); var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
frame: true,
title: 'Login Window',
bodyStyle: 'padding:5px 5px 0',
width: 350,
x: 400,
y: 300,
renderTo: bd,
defaults: { width: 230 },
defaultType: 'textfield', items: [{
id: 'userid',
fieldLabel: 'UserId',
name: 'first'
}, {
id: 'pass',
fieldLabel: 'Password',
name: 'last'
}
], buttons: [{
text: 'Login',
handler: function() {
var user_id = Ext.getDom('userid').value;
var pass = Ext.getDom('pass').value;
Ext.Ajax.request({
url: "Login.ashx",
method: "post",
params: { userid: user_id, password: pass },
success: function() { window.open("index.aspx"); }
});
}
}]
});
simple.render(document.body);
});
</script>
解决方案 »
- 在线等:急求jquery页面加载后,事件对象无效问题!
- +++++++js 用于百度编码问题,大牛来帮个忙,谢谢 +++++
- 还不是抄来的...帮忙解释解释.~~function toggle_collapse(objname, unfolded)
- 弹出层的问题,想实现qq邮箱那样的效果
- setInterval问题, setInterval无效,
- 如果设置动态添加的单元格自动换行?在线等待!!!
- 求,在一个INPUT中直接输入123*4856+(123*45),再在另一个INPUT中得到计算的值
- !!!这行什么意思-》timerID = setTimeout("showtime()",1000);
- html实体转换
- Node.js怎样response:循环执行多个sql查询语句后的结果集
- 向div中插入js
- 请问如何实现点击span下面的a显示出来
<script type="text/javascript">
Ext.onReady(function() { Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var bd = Ext.getBody();
bd.createChild({ tag: 'h2', html: '' }); var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
frame: true,
title: 'Login Window',
bodyStyle: 'padding:5px 5px 0',
width: 350,
x: 400,
y: 300,
renderTo: bd,
defaults: { width: 230 },
defaultType: 'textfield', items: [{
id: 'userid',
fieldLabel: 'UserId',
name: 'first'
}, {
id: 'pass',
fieldLabel: 'Password',
name: 'last'
}
], buttons: [{
text: 'Login',
handler: function() {
var user_id = Ext.getDom('userid').value;
var pass = Ext.getDom('pass').value;
Ext.Ajax.request({
url: "Login.ashx",
method: "post",
params: { userid: user_id, password: pass },
success: function() { window.open("index.aspx"); }
});
}
}]
});
document.body.style.textAlign="center";
simple.render(document.body);
document.body.style.marginTop= (document.body.clientHeight - simple.getForm().getEl().dom.clientHeight)/2;
});
</script>
但是不行呀,结果title居中了,但是面板还是在左上角。
document.body.style.marginLeft= (document.body.clientWidth - simple.getForm().getEl().dom.clientWidth)/2;
document.body.style.marginTop= (document.body.clientHeight - simple.getForm().getEl().dom.clientHeight)/2;
还有,我想把密码写成*****的形式,应该怎么做呀?
加inputType : 'password',<script type="text/javascript">
Ext.onReady(function() { Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var bd = Ext.getBody();
bd.createChild({ tag: 'h2', html: '' }); var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
frame: true,
title: 'Login Window',
bodyStyle: 'padding:5px 5px 0',
width: 350,
x: 400,
y: 300,
renderTo: bd,
defaults: { width: 230 },
defaultType: 'textfield', items: [{
id: 'userid',
fieldLabel: 'UserId',
name: 'first'
}, {
id: 'pass',
fieldLabel: 'Password',
inputType:'password',
name: 'last'
}
], buttons: [{
text: 'Login',
handler: function() {
var user_id = Ext.getDom('userid').value;
var pass = Ext.getDom('pass').value;
Ext.Ajax.request({
url: "Login.ashx",
method: "post",
params: { userid: user_id, password: pass },
success: function() { window.open("index.aspx"); }
});
}
}]
});
simple.render(document.body);
document.body.style.marginLeft= (document.body.clientWidth - simple.getForm().getEl().dom.clientWidth)/2;
document.body.style.marginTop= (document.body.clientHeight - simple.getForm().getEl().dom.clientHeight)/2;
});
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>User Login</title> <link rel="stylesheet" type="text/css" href="./ext/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="./ext/resources/css/xtheme-gray.css">
<script type="text/javascript" src="./ext/adapter/ext/ext-base.js"></script> <!-- ENDLIBS --> <script type="text/javascript" src="./ext/ext-all.js"></script></head>
<body> <script type="text/javascript">
Ext.onReady(function() { Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var bd = Ext.getBody();
bd.createChild({ tag: 'h1', html: '' }); var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
frame: true,
title: 'Login Window',
bodyStyle: 'padding:5px 5px 0',
width: 350,
x: 500,
y: 300,
renderTo: bd,
defaults: { width: 230 },
defaultType: 'textfield', items: [{
id: 'userid',
fieldLabel: 'UserId',
name: 'first'
}, {
id: 'pass',
fieldLabel: 'Password',
inputType: 'password',
name: 'last'
}
], buttons: [{
text: 'Login',
handler: function() {
var user_id = Ext.getDom('userid').value;
var pass = Ext.getDom('pass').value;
Ext.Ajax.request({
url: "Login.ashx",
method: "post",
params: { userid: user_id, password: pass },
success: function() { window.open("index.aspx"); }
});
}
}]
});
document.body.style.textAlign = "center";
simple.render(document.body);
document.body.style.marginLeft = (document.body.clientWidth - simple.getForm().getEl().dom.clientWidth) / 2;
document.body.style.marginTop = (document.body.clientHeight - simple.getForm().getEl().dom.clientHeight) / 2;
});
</script></body>
</html>
这是微软自己的东西不兼容,改回IE7就没问题了。
然后将simple.render(document.body)改为simple.render('myDiv');