我一直在我的网站上使用以下出生日期JavaScript功能多年来突然它现在会弹出一个我不需要具有该值的弹出窗口?我只需要在p标签内显示值。
<p>I'm xxxxx. I have over
<script>
var dob='20050613';
var year=Number(dob.substr(0,4));
var month=Number(dob.substr(4,2))-1;
var day=Number(dob.substr(6,2));
var today=new Date();
var age=today.getFullYear()-year;
if(today.getMonth()<month || (today.getMonth()==month && today.getDate()<day))
alert(age);
document.write(''+age+'');
</script>
years' experience xxxx.</p>
有什么想法吗?提前致谢。
答案 0 :(得分:0)
请尝试以下代码:
<p>I'm xxxxx. I have over
<script>
var dob='20050613';
var year=Number(dob.substr(0,4));
var month=Number(dob.substr(4,2))-1;
var day=Number(dob.substr(6,2));
var today=new Date();
var age=today.getFullYear()-year;
if(today.getMonth()<month || (today.getMonth()==month && today.getDate()<day))
//alert(age);
document.write(age);
//return(age);
</script>
years' experience xxxx.</p>
主要更改是删除alert()
功能。