【 生命是幻觉 】

『 Life is an unreturnable pilgrimage 』- One day I will fly away, leave all this to yesterday.

统计

MyHome

最新评论

网页代码上遇见的奇怪问题!非常奇怪!【女生是菜鸟】


—   代码感觉上没错,但是显示到if的时候没有执行(我用了很多方法,它就是不执行!无语ING)。—

ps:哥哥姐姐们``帮帮偶吧``偶快在沉默的电脑前灭亡了!(本人一直在线,求解答!)



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>个人资料</title>
<script language="javascript">
function Focus()
{
    document.myForm.myName.value
="";
}

function Blur()
{
    name
=document.myForm.myName.value;
    
if(isNaN(name)==false)
    
{
        alert(
"对不起,名字不能全部是数字!");
    document.myForm.myName.focus();
    }

}

function openwindow()
{
    
var userName=document.myForm.myName.value;
    document.write(
"<h1><center>您的详细资料</center></h1>");
    document.write(
"<br><p><center>您的姓名是:"+userName+"</center></p>");
    
if(document.myForm.jc.checked==true)
    
{
        document.write(
"<p><center>您具有:大专学历</center></p>");
    }

    
if(document.myForm.bos.checked==true)
    
{
        document.write(
"<p><center>您具有:本科学历</center></p>");
    }

    
if(document.myForm.mos.checked==true)
    
{
        document.write(
"<p><center>您具有:硕士学历</center></p>");
    }

}

</script>
<style type="text/css">
</style>
</head>

<body>
<form name="myForm">
<table width="289" height="168" border="0" align="center" cellpadding="0" cellspacing="0">
<!--<th align="center" style="font-size:30px">祥龙娱乐网页</th>-->

<caption align="top" style="font-size:30px"><b>祥龙娱乐网页</b></caption>
<tr>
<td height="35">姓名*</td>
<td colspan="2"><input name="myName" type="text" size="30" maxlength="30" value="名字由大写与小写字母组成" onfocus="Focus()" onblur="Blur()"/></td>
</tr>
<tr>
<td height="29" colspan="3" align="center">学历</td>
</tr>
<tr>
<td height="30"><div><input name="jc" type="checkbox" id="jc" value="JuniorCollege"/>大专</div></td>
<td><div><input name="bos" type="checkbox" id="bos" value="BachelorOfScience" />理学学士</div></td>
<td><div><input name="mos" type="checkbox" id="mos" value="MasterOfScience" />理学硕士</div></td>
</tr>
<tr>
<td colspan="3" align="center"><input name="show" type="button" value="显示" onclick="openwindow()" /></td>
</tr>
</table>
</form>
</body>
</html>

posted on 2008-03-11 22:10 stephanie瑶瑶 阅读(356) 评论(5)  编辑 收藏 引用 所属分类: OnTheWayToSuccess

评论

# re: 网页代码上遇见的奇怪问题!非常奇怪!【女生是菜鸟】 2008-03-11 23:10 lot

估计是document.write引起的问题。原因还不清楚,而且firefox没有这个问题,我的解决方法是:

var out = "";
out += "<h1><center>您的详细资料</center></h1>";
out += "<br><p><center>您的姓名是:"+userName+"</center></p>";
if(document.myForm.jc.checked==true) {
out += "<p><center>您具有:大专学历</center></p>";
}
document.write(out);  回复  更多评论   

# re: 网页代码上遇见的奇怪问题!非常奇怪!【女生是菜鸟】 2008-03-11 23:20 lot

感觉和document.write的工作机制有关。IE的d.write可能会重写当前的document,具体机制因很少用这个函数,还不清楚。一般是考虑用innerHtml系来完成这类任务。  回复  更多评论   

# re: 网页代码上遇见的奇怪问题!非常奇怪!【女生是菜鸟】 2008-03-11 23:29 stephanie瑶瑶

IE的d.write可能会重写当前的document

能具体说明一下吗?  回复  更多评论   

# re: 网页代码上遇见的奇怪问题!非常奇怪!【女生是菜鸟】 2008-03-12 07:26 lot

当 document.write 作用于已经加载完毕的文档,比如上文中的 openwindow 事件中时,它会先重写整个文档。IE可能再重写前会先清除整个文档。

对于博主的代码来说。IE就是把现用的html和js代码全部清除后,再输出“您的详细资料”。这样document后面的if已经被write函数从文档中清除了,所以就不会执行。

document.write的工作机制还没有找到微软或w3c的官方论证,所以还是猜测。参考这篇文章:
http://java-programming.suite101.com/article.cfm/javascript_documentwrite_tutorial  回复  更多评论   

# re: 网页代码上遇见的奇怪问题!非常奇怪!【女生是菜鸟】 2008-03-12 07:30 lot

http://javascript.about.com/library/blwrite.htm
这篇文章也说:当前页面加载完毕后,再执行任何document.write都会建立一个新的document并覆盖掉当前页面的所有内容。  回复  更多评论   

只有注册用户登录后才能发表评论。