我使用div標籤製作盒子。用戶輸入將從提示框中獲取,並將顯示在固定尺寸的div標籤中。如果沒有輸入,那麼div就不會顯示。當沒有輸入時會隱藏div div
但是,當我沒有在提示框中輸入任何內容時,即使我已指定else
條件下其可見性設置爲隱藏,仍會顯示空的div。
我認爲該程序未輸入if
語句的else
條件,以將div的可見性設置爲隱藏。
的JavaScript:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> css//the js file..
var person1;
function getdata()
{
person1=prompt("Please enter your data 1","Sample 1",max="5");
}
function displayResult()
{
var table1=document.getElementById("table1");
table1.innerHTML=person1;
if(person1.value!="")
{
$("#table1").css({"border-color": "#000000",
"border-width":"1px",
"border-style":"solid",
"visibility" : "visible",
//"position" :"fixed",
//"resize":"both",
"overflow":"auto",
"width":"60px",
//"maxlength":"10",
"height": "80px",
"top": "30px",
"left" : "80px"});
}
else
{
alert("hello");
("#table1").css({"border-color": "#000000",
"border-width":"0px",
"border-style":"solid",
"visibility" : 'hidden',
//"position" :"fixed",
"resize":"both",
"overflow":"auto",
"width" :"60px",
"height" : "80px",
"top": "30px",
"left" : "80px"});
}
}
HTML:
<body>
<form>
<div id="table1" width="1%" height="10%" style="visibility:hidden"></div>
</form>
<button type="button" id="button" onclick="getdata()">Insert data</button>
</body>
這裏是jsfiddle
試過...當我輸入一些數據,然後框沒有得到顯示,當沒有數據輸入時,我得到錯誤「#table1」.css不是沒有輸出功能... – Lucy 2013-04-27 08:41:21
什麼時候調用displayResult()函數? – 2013-04-27 08:45:18
當用戶點擊按鈕或單選按鈕時。 – Lucy 2013-04-27 09:24:45