javascript - js 函数确实负责设置 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="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>

请帮忙。

最佳答案

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

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

在标准模式下,大多数浏览器将遵循 CSS 规范并处理类似 height: 27 的内容。作为要忽略的错误而不是要更正为 height: 27px 的错误.

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

举一个例子:

id.style.height=150;

应该是:

id.style.height = "150px";

您至少在其他地方犯了类似的错误。

关于javascript - js 函数确实负责设置 doctype 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6518180/

相关文章:

html - float 不按预期工作

c# - 如何在 C# 中将文档类型添加到新的 XML 文件

validation - RDFa 面包屑导航和验证器的正确文档类型

javascript - 来自父窗口的跨域window.close事件

javascript - 鼠标事件未在 html5 Canvas 上触发

javascript - ng-repeat - 在 html 循环中计数

javascript - 如何使用参数调用继承的 JavaScript 构造函数?

html - 链接我的 favicon.ico 文件,但出现问题

c# - 解析 HTML 页面,包括所有 css 样式

html - Chrome/Edge 和 Firefox 中的不同图像渲染