简答题 Web程序设计
题号 #5101632

1.<html>
<head>
<script type="text/javascript" >
function closeWin(){
//在此处添加代码
// **********Found**********
if(________________("确定要退出吗?")){
// **********Found**********
________________;
}
}
function morning(){
now = new Date();
// **********Found**********
hour = _______________; 
if (hour < 9){window.status="早上好!"}
else {window.status="下午好!";}}
</script>
</head>
<!-- **********Found********** -->
<body ________________="morning()">
<!-- **********Found********** -->
<input type="button" value="关闭窗口" onclick="______________"/>
</body>
</html>
本题的功能是:在早上9点前则在窗囗状态栏中显示“早上好”,否则显示“下午好”。点击页面中的按钮时,弹出对话框提示“确定要退出吗”,确定后自动关闭窗口。
2.<html>
<head>
<script>
function foo()
{
var str = reverse('a,b,c,d,e,f,g');
alert(str);
if (str == 'g,f,e,d,c,b,a')
alert('成功');
else alert('失败');
}
function reverse(str)
{
// 在此处加入代码,完成字符串翻转功能
// **********Found**********
var spl = str._____________(',');
var newstr="";
// **********Found**********
for(i=____________;i>=0;i--)
{
// **********Found**********
newstr+=____________+',';
}
// **********Found**********
newstr=newstr._____________(0,newstr.length-1)
return newstr;
}
</script>
</head>
<body>
<input type="button" value="str" onclick="foo()" />
</body>
</html>
本题的要求是:点击页面中的按钮,将'a,b,c,d,e,f,g'字符串输出为'g,f,e,d,c,b,a',弹出警告框显示"成功"。

进入在线模考

参考答案

暂无

答案解析

1.答案:(1)confirm;(2)window.close();(3)now.getHours();(4)onload;(5)closeWin()。 
解析:本题需要当系统时间在早上9点前则在窗口状态栏中显示“早上好”,否则显示“下午好”,因此在程序中,弹出对话框为 confirm,因此(1)处填写coπfirm,退岀,关闭窗口,因此(2)处填 window.close(),获取当前时间用getHours()函数,由于是面向对象,故(3)处填写now.getHours(),本题要求自动调用函数因此加入onload时间,故(4)处填写onload,在点击事件中,要通过点击调用closewino函数,因此(5)处填写closeWin()。 
2.答案:(1)split;(2)spl.length-1;(3)spl[i];(4)substring。 
解析:本题要求点击页面中的按钮,将'a,b,c,d,e,f,g'字符串输出为'g,f,e,d,c,b,a',弹岀警告框显示“成功”,本题在foo()函数中调用reverse()函数,此函数的功能是实现字符串翻转,在此函数中,首先是使用split将字符串分割,故(1)填split并生成数组,并将其赋值给sql变量,通过length属性得到字符串长度,获得数组中的每个值,由于是从0开始的,因此获得长度需减1,故(2)填spl.length-1,(3)填spl[i],而substring()返回位于string对象中指定位置的子字符串,substring方法返回一个包含从start到最后(不包含end)的子字符串的字符串,因此(4)填写substring。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考