我试图对齐文本框按键事件页面中心的文本框,但我只能用下面给出的代码放大文本框的大小.
<title></title>
<script type="text/javascript">
function resize(selectObj) {
selectObj.style.height = '400px';
selectObj.style.width = '800px';
selectObj.style.padding = '10px 10px 10px 10px';
selectObj.style.position = 'absolute';
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt" runat="server" TextMode="MultiLine" onkeypress="resize(this);">
</asp:TextBox>
</div>
</form>
</body>
</html>
发布于 2013-11-01 06:13:09
这绝对对你有帮助
$( "#txt" ).keypress(function() {
$(this).css({
'position': 'absolute',
'left': ($(window).width() / 2 - $(this).width() / 2) + 'px',
'top': ($(window).height() / 2 - $(this).height() / 2) + 'px',
});
发布于 2013-10-08 05:37:22
你可以这样做
$( "#txt" ).keypress(function() {
$("#maindiv").css({'display' : 'block', 'text-align' : 'center'});
});
演示Fiddle
屏幕中心更新
$( "#txt" ).keypress(function() {
$(this).css('margin-left', ($(window).width() / 2));
});
屏幕演示固定中心
发布于 2013-10-08 09:41:41
您可以使用绝对定位来对其进行居中。您应该考虑文本框的宽度和高度:
$( "#txt" ).keypress(function() {
$(this).css({
'position': 'absolute',
'left': ($(window).width() / 2 - $(this).width() / 2) + 'px',
'top': ($(window).height() / 2 - $(this).height() / 2) + 'px',
});
https://stackoverflow.com/questions/19239749
复制相似问题