87,910
社区成员
发帖
与我相关
我的任务
分享
window.onload = function ()
{
var oinput = document.getElementById('oint');
var oput = document.getElementById('put');
var spacecheck = /\s/ig;
oput.onclick = function ()
{
var optm = prompt('请问是这样吗?');
if(optm!=null)
{
oint.value = optm;
}
else if(optm == null||optm =="")
{
alert("空值");
}
}
}
if(optm!=null)
{oint.value = optm;}
else if(optm == null||optm =="")
{alert("空值");
}
这样写不对,
当什么都不输入点击确定时,optm获取到的是""而不是null,所以还是执行了赋值,而没有进入else,
改成楼上的那样就行。
if(optm == null||optm =="")
{
alert("空值");
} else {
oint.value = optm;
}