1.31.JavaScript中的提示框有哪些,请列举出来
参考答案:
JavaScript中的提示框有:警告框,确认框,提示框,代码表示如下:
alert("我是警告框");
confirm("确认框");
prompt("提示框","你的密码与你的生日有关");
1.32.如何利用JavaScript在html中添加一个div?
参考答案:
利用JavaScript在html中添加一个div的代码如下所示:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function add(){
var d=document.getElementById("aaa");
d.innerHTML='<div style="border:1px solid red;width:200px;height:200px;">添加div</div>
}
</script>
</head>
<body id="aaa">
<input type="button" value="添加" onclick="add();"/>
</body>
</html>
1.33.怎样用JavaScript提交一个form?
参考答案:
使用JavaScript提交表单的代码如下所示:
<html>
<head>
<title>怎样用JavaScript提交一个form?</title>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<script type="text/javascript">
function save(){
document.myform.submit();
}
</script>
</head>
<body>
<form id="myform" name="myform" action="save.html">
<input type="text" name="user" id="username"/><br/>
<input type="password" name="pwd" id="userpwd"/><br/>
<input type="button" value="提交" onclick="save();/>
</form>
</body>
</html>
1.34.使用JavaScript在html页面中id为mytable的div中动态生成一个2行2列的表格
参考答案:
使用JavaScript在html页面中id为mytable的div中动态生成一个2行2列的表格代码如下所示:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function add(){
var d=document.getElementById("aaa");
d.innerHTMl='<table border="1" width="150px" height=120px align="center" cellspacing="0"><tr><td>a</td></tr><tr><td>b</td></tr><tr><td>c</td></tr><tr><td>d</td></tr></table>';
}
</script>
</head>
<body>
<div id="aaa" style="border:1px solid red;width:200px;height=200px;"></div>
<input type="button" value="添加" onclick="add();"/>
</body>
</html>
1.35.Web页面开发,有”Btn_set”按钮和”Btn_xsbh”的文本框,用JS编程,点击按钮,当文件框内容为空时,为文本框赋值”Test”,不为空时,让文本框不可再输入
参考答案:
<html>
<head>
<script type="text/javascript">
function f(){
var s=document.getElementById("aaa");
if(s.value.length==0){
s.value="Test"
}else{
s.disabled=true;
}
}
</script>
</head>
<body>
<input type="button" name="user" value="Btn_set" onclick="f();">
<input type="text" name="Btn_xsbn id="aaa">
</body>
</html>
1.36.输入N个数字,用逗号隔开.当你按提交按钮时出来的数字按照顺序排序(什么顺序都可以)
参考答案:
<html>
<head>
<title>Q036.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
//数组排序
function operateArray(t){
//拆分为数组
var array = document.getElementById("txtNumbers").value.split(",");
array.sort(sortFunc);
alert(array.toString());
}
function sortFunc(a,b){
return a - b;
}
</script>
</head>
<body>
<input type="text" id="txtNumbers" value="12,4,3,123,51"/>
<input type="button" value="数组排序(数值)" onclick="operateArray();"/>
<br>
</body>
</html>
1.37.HTML中<div></div>
和<span></span>
的区别.请写出至少5种常见的http状态码以及代表的意义
参考答案:
1.多个<div>
内的元素会换行显示,多个<span>
内的元素显示在同一行.
2.5种常见的http状态码以及代表的意义如下是:
1)200 OK:请求已经成功,请求所希望的响应或数据体将随此响应返回.
2)302 Found:请求的资源现在临时从不同的URI响应请求.
3)404 Not Found:请求失败,请求所希望得到的资源未被在服务器上发现.
4)500 Internal Server Error:服务器遇到一个未曾预料的状况,导致了它无法完成对请求的处理.
5)400 Bad Request:1)语义有误,当前请求无法被服务器理解.除非进行修改,否则客户端不应该重复提交这个请求.2)请求参数有误.
1.38.用JavaScript动态生成一张图片,图下面是字符(图片人物名字)
参考答案:
<html>
<head>
<title>Q038.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="javascript">
function SelectPic(cc){
var pIC = document.createElement("img");
ID = pIC.id="pic"+Math.random()+cc.src+Math.random();//避免id相同图片不显示
pIC.alt=ID;//图片不显示时的提示
pIC.width=cc.width;
pIC.height=cc.height;
pIC.onclick=function(){
//调用函数
SelectPic(this)
}
document.getElementById("PicC").appendChild(pIC);
document.getElementById(ID).src=cc.src;
document.getElementById("picTxt").innerHTML="李大钊";
}
</script>
</head>
<body>
<form id="form1">
<div>
<img src="images/7.jpg" name="pic3" onclick="SelectPic(this)" style="height:150px;width:90px"/>
<div id="PicC"></div>
<div id="picTxt"></div>
</div>
</form>
</body>
</html>
1.39.请用HTML标签写出如下图所示的登录框
参考答案:
<html xmlns="http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Q039</title>
</head>
<body class="index">
<div class="login_box">
<table>
<tr>
<td class="login_info">账号:</td>
<td><input name="info.adminCode" type="text" class="width150"/></td>
</tr>
<tr>
<td class="login_info">密码:</td>
<td><input name="info.password" type="password" class="width150"/></td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="重置"/>
<input type="button" value="登录"/>
</td>
</tr>
</table>
<div>
</body>
</html>
1.40.有下面HTML代码,请用JS获取checkbox,radio,select选中的值
<html>
<head>
</head>
<body>
<form action="#">
<div>
爱好:
<input type="checkbox" name="hobby" value="篮球">篮球;
<input type="checkbox" name="hobby" value="音乐">音乐;
<input type="checkbox" name="hobby" value="跑步">跑步
</div>
<div>
性别:
<input type="radio" name="gender" value="男">男;
<input type="radio" name="gender" value="女">女
</div>
<div>
年龄:
<select>
<option value="">请选择</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
</select>
</div>
</form>
</body>
</html>
参考答案:
<html>
<head>
<title>Q040.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function foo(){
var chkObj = document.getElementsByName("hobby");
for(var i=0;i<chkObj.length;i++){
if(chkObj[i].checked){
alert("复选框:"+chkObj[i].value);
}
}
var radObj = document.getElementsByName("gender");
for(var i=0;i<radObj.length;i++){
if(radObj[i].checked){
alert("单选按钮:"+radObj[i].value);
}
}
var selObj=document.getElementsByTagName("select")[0];
for(var i=0;i<selObj.length;i++){
if(selObj[i].selected){
alert("下拉列表框:"+selObj[i].value);
}
}
}
</scripy>
</head>
<body>
<form action="#">
<div>
爱好:
<input type="checkbox" name="hobby" value="篮球">篮球;
<input type="checkbox" name="hobby" value="音乐">音乐;
<input type="checkbox" name="hobby" value="跑步">跑步
</div>
<div>
性别:
<input type="radio" name="gender" value="男">男;
<input type="radio" name="gender" value="女">女
</div>
<div>
年龄:
<select>
<option value="">请选择</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
</select>
</div>
<div>
<input type="button" value="查看" onclick="foo()">
</div>
</form>
</body>
</html>