我有一個測試php文件,其中有50個按鈕(只是爲了製作一張大桌子)。當第一個按鈕被點擊時,我想要一個JQuery對話框,其中有一個html文本框可以通過JQuery打開。現在,代碼打開文本框,但在屏幕的底部。在桌子下面。我的目標是在當前屏幕的中心打開,即不被用戶向下滾動。這裏是我的代碼:沒有出現在當前屏幕中心的JQuery對話框
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.js">
**<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />**
</script>
<script type="text/javascript" >
$(document).ready(function(){
showClick();
});
function showClick(){ $('#comment0').click(function(ez) {
$('#0').dialog('open');
ez.preventDefault();
return false;
});
$('#0').dialog({
autoOpen: false,
modal: true,
resizable: false,
title: 'haha',
height: 'auto',
draggable: true,
position: 'center'
}); }
</script>
</head>
<body>
<?php
?><div id="0"><input type="text" ></div>
<?php
echo "<table>";
for($i=0; $i<50; $i++) {?>
<tr>
<td><input type="button" class="comment0" value="Comment" id="comment0"></td>
</tr>
<!--div id="<?php echo $i; ?>" style="display :none"><input type="text" ></div-->
<?php
} ?>
<?php
echo "</table></body></html>";
?>
注:這是一個快速骯髒的代碼,我只是測試JQuery的大表大小的行爲。我在這裏做錯了什麼?
感謝您的幫助!
編輯:原來你必須導入JQuery CSS。現在的問題是,該對話框在表的中心打開。無論如何,對話框打開在當前屏幕的中心嗎?謝謝!
什麼?太簡單!哈哈。這東西弄亂了我的頭兩天!非常感謝你!! – javaCity
等待..這現在打開在表的中心。反正有沒有這樣做?謝謝!我將編輯我的原始文章。 – javaCity
@javaCity dialog()has [position()](http://stackoverflow.com/questions/3816250/can-i-centre-a-jquery-ui-dialog-to-a-div) – StuartLC