Javascript js函数负责设置doctype规范

Javascript js函数负责设置doctype规范,javascript,html,doctype,Javascript,Html,Doctype,我是javascript新手。我尝试创建此页面,但不知何故,shorten函数无法提供doctype规范。我正在使用此函数 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> 但如果没有指定,它可以正常工作以下是文件的完整代码: <html> <head> <script language="jav

我是javascript新手。我尝试创建此页面,但不知何故,shorten函数无法提供doctype规范。我正在使用此函数

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

但如果没有指定,它可以正常工作
以下是文件的完整代码:

<html>
<head>
<script language="javascript" >
function show(){
document.getElementById("dynamic").style.display="block";
document.getElementById("dynamic").style.opacity=1;
document.getElementById("dynamic").innerHTML="<table><tr>\n\t<td>Enter current password:</td><td><input type=\"password\" name=\"ppass\" size=\"45\"></td></tr><tr>\n<td>Enter new password:</td><td><input type=\"password\" name=\"npass1\" size=\"45\"></td></tr><tr>\n<td>Confirm password:</td><td><input type=\"password\" name=\"npass2\" size=\"45\"></td></tr><tr><td colspan=2><input type=submit value=\"Save\"></tr></table>\n";
document.setting.question[1].checked=true;
}
function hide(){
    if(document.forms.setting.question[0].checked!=true){
        fade("dynamic",50);
        }
    }
function appear(){
    document.getElementById("dynamic").style.display="block";
    document.getElementById("dynamic").style.opacity=1;
    document.getElementById("dynamic").innerHTML="<table><tr>\n\t<td>Enter password:</td><td><input type=\"password\" name=\"ppass\" size=\"45\"></td></tr><tr><td>Security Question:</td><td><input type=\"text\" name=\"ques\" size=\"100\"></td></tr><tr><td>Answer:</td><td><input type=\"password\" name=\"ans\" size=\"10\"></td></tr><tr><td colspan=2><input type=submit value=Save></tr></table>";
    document.setting.pass[1].checked=true;
    }
function disappear(){
    if(document.forms.setting.pass[1].checked){
        slide("dynamic",50);
        }
    }
function fade(id,time){
    var i=0;
    for(;i<10;i++){
        setTimeout("document.getElementById('dynamic').style.opacity-=0.1",(i*time));
        }
    i--;
    setTimeout("gayab("+id+")",(i*time));
    }
function gayab(id){
    id.style.display="none";
    id.innerHTML="";
    id.style.opacity=1;
    }
function slide(id,time){
    var i=1;
    document.getElementById(id).style.height=150;
    var b=document.getElementById(id).style.height;
    for(;i<15;i++){
        var j="shorten("+id+","+i+")";
        var k=i*time;
        setTimeout(j,k);
        }
    var j="gone("+id+")";
    var k=i*time;
    setTimeout(j,k);
    }
function shorten(id,i){
    id.style.height=(15-i)*10;
    }
function gone(id){
    id.style.display="none";
    id.style.height=150;
    }
</script>
<noscript>You are Using an Outdated Browser.<br>Please Update Your Browser</noscript>
<style>
.options{float:left;}
#dynamic{float:right;background-color:rgb(210,205,236);height:150px;opacity:1;overflow:hidden;width:720px;display:none;}
.nofloat{clear:both;}
</style>
<title>Settings</title>
</head>
<body>

<p align=right><a href=home.php>HOME</a> <a href=newpass.php>Change Password</a> <a href=logout.php>Log Out</a></p>
<form action="changepass.php" method="post" name="setting">
<div class=options>
<table>
<tr>
    <td>Change Password:</td>
    <td><input type="radio" name="pass" onClick="show();" value="1" id="Yes"><label for="Yes">Yes</label></td>
    <td><input type="radio" name="pass" onClick="hide();" value="0" id ="No" CHECKED><label for="No">No</label><br></td>
</tr>
<tr>
    <td>Change Security Question:</td>
    <td><input type="radio" name="question" onClick="appear();" value="1" id="yes"><label for="yes">Yes</label></td>
    <td><input type="radio" name="question" onClick="disappear();" value="0" id="no" CHECKED><label for="no">No</label></td>
</tr>
</table>
</div>
<div id="dynamic"></div>
<div class=nofloat>
<a href=logout.php>Logout</a>
</div>
</form>
</body>
</html>

函数show(){
document.getElementById(“动态”).style.display=“块”;
document.getElementById(“动态”).style.opacity=1;
document.getElementById(“动态”).innerHTML=“\n\t输入当前密码:\n输入新密码:\n确认密码:\n”;
document.setting.question[1]。选中=true;
}
函数hide(){
if(document.forms.setting.question[0]。选中!=true){
淡出(“动态”,50);
}
}
函数出现(){
document.getElementById(“动态”).style.display=“块”;
document.getElementById(“动态”).style.opacity=1;
document.getElementById(“动态”).innerHTML=“\n\t密码:安全问题:答案:”;
document.setting.pass[1]。checked=true;
}
函数消失(){
if(document.forms.setting.pass[1]。选中){
幻灯片(“动态”,50);
}
}
功能衰减(id、时间){
var i=0;

对于(;i您正在设置一个文档类型,该文档类型期望您的页面能够,但是没有。例如,您应该使用不同的
DOCTYPE

您的DOCTYPE(尽管不适合文档,因为它不包含框架集)正在触发标准模式

这是一件好事,因为它大大减少了不同浏览器之间(以及浏览器和标准之间)的不一致性

在标准模式下,大多数浏览器将遵循CSS规范,并将
height:27
等错误视为可忽略的错误,而不是将错误更正为
height:27px

您的代码(可能还有其他代码,您已经发布了很多代码)的明显问题是,您正在使用JavaScript将数字分配给CSS属性……而数字没有单位

仅举一个例子:

id.style.height=150;
应该是:

id.style.height = "150px";
您至少在另一个地方犯了类似的错误。

您使用的是过时的浏览器。
请更新您的浏览器
-人们可以在没有“过时”浏览器的情况下禁用JavaScript。人们也可以使用最新版本的浏览器(例如Lynx)并且没有JavaScript支持。一般来说,你应该这样做,如果你做不到这一点,那么你应该确保你的错误消息至少是准确的。我不能强调的一点是,你使用
id
有时引用字符串,有时引用元素。这真的不推荐使用
setTimOut
code会让事情变得更加混乱——无论您想传递字符串还是DOM节点,都可以使用类似于
setTimeout(function(){slide(“dynamic”);},1000)
的表达式,而不是这些
eval
-ish表达式。