HTML学习笔记四

时间:2024-01-11 22:12:44

今日学习内容为:

1.文本域操作

<html>
<head>
<meta charset="utf-8"/>
<title>JavaScript4</title>
<script type="text/javascript" language="javascript">
function fun()
{
var max = 20;
var curr = document.getElementById("note").value.length;
if(curr < max)
{
document.getElementById("msg").innerHTML = "您可以输入" + (max - curr) + "个字";
document.getElementById("sub").disabled = false;
}
else
{
document.getElementById("msg").innerHTML = "<font color=\"red\">您的输入内容过长,请修改。</font>";
document.getElementById("sub").disabled = true;
}
}
</script>
</head>
<body>
<form action="javascript3.html" name="myform">
<textarea name="note" cols="30" rows="6" onkeydown="fun()" onkeyup="fun()">
</textarea>
<br/>
<span id="msg">您可以输入20个字</span>
<input type="submit" name="sub">
</form>
</body>
</html>

  

2.表格操作

<html>
<head>
<title>JavaScript5</title>
<script type="text/javascript" language="javascript">
function createTable()
{
document.write("<table border=\"1\">");
for(var i=1;i<=9;i++)
{
document.write("<tr>");
for(var j=1;j<i;j++)
{
document.write("<td>"+i+"*"+j+"="+(i*j)+"</td>"); }
for(var j=1;j<9-i;j++)
{
document.write("<td> </td>")
}
document.write("</tr>");
}
}
</script>
</head>
<body>
<input type="button" value="生成乘法口诀" onclick="createTable()"/>
</body>
</html>