我正在使用 div 标签制作一个盒子。用户输入将从提示框中获取,并将显示在固定尺寸的 div 标签中。如果没有给出任何输入,则根本不会显示 div。
但是,当我没有在提示框中输入任何内容时,仍会显示空 div,即使我已指定将else
其可见性设置为隐藏的条件。
我认为程序没有进入将 div 的可见性设置为隐藏else
的语句的条件。if
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