JavaScript 测试题 (2021-6-21)

本文介绍了JavaScript的基础语法,包括变量、数据类型、条件语句、循环、函数以及DOM操作。通过实例展示了如何操作图片使其在3秒后消失,还讨论了数组、定时器、事件及对象属性的遍历等概念。同时,文章涵盖了JavaScript中的数组操作方法,如随机获取元素,以及数组和对象的遍历技巧。此外,还讲解了日期对象和字符串操作的相关知识。
摘要由CSDN通过智能技术生成
  1. 3 秒后图片消失,应该使用哪个方法?
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<img src="images/桌面1.png" >
	</body>
	<script type="text/javascript">
		var oImg = document.querySelector("img")
		setTimeout(function(){
			oImg.style.display = "none"
		},3000)
	</script>
</html>
  1. 下列哪个是错误的写法?【A】
    A:console.log(document.html);【正确写法是document.documentElement
    B:console.log(document.body);
    C:console.log(document.title);
    D:console.log(document.head);
  2. 以下选项,能够正确随机获取数组中元素的是 var arr = [“张三”,“李四”,“王二”,“二哈”]【AB】
    A Math.round(Math.random() * (arr.length-1) )
    B parseInt(Math.random() * arr.length )
    C Math.round(Math.random() * (arr.length) )
    D parseInt(Math.random() * (arr.length-1) )
  3. 以下函数中,哪些是在调用后,原数组本身也被改变,不返回新数组?【ABCD】
    A push()
    B pop()
    C shift()
    D unshift()
  4. 关于nodeValue描述错误的是?【C】
    A 属性节点的nodeValue是属性值
    B 文本节点的nodeValue是文本本身
    C 元素节点的nodeValue是数字
    D 元素节点的nodeValue是标签名
  5. JS提供的定时器有哪些?【AC】
    A setInterval()
    B clearInterval()
    C setTimeout()
    D clearTimeout()
  6. window对象的子对象有?【ABD】【还有一个screen】
    A document
    B location
    C href
    D history
  7. 下列哪些方法可以遍历数组?【ABC】
    A for
    B for-in
    C do-while
    D for-by
  8. 以下哪些操作可以刷新浏览器?【AB】
    A window.history.go(0)
    B window.location.reload()
    C window.open()
    D window.history.back(0)
  9. 在JavaScript中,可以实现跳转的是?【ABCD】
    A window.open()
    B window.location.href
    C window.location.assign()
    D window.location
  10. 下列哪些是属于DOM操作的方法?【BD】
    A removeChildren
    B appendChild()
    C children
    D removeChild()
  11. 下面结果返回值为4的有?【ABD】
    A Number(“4”)
    B parseInt(“4aa11”)
    C Math.floor(3.5)
    D Math.round(3.5)
  12. 对象可以通过哪种方式进行对象属性的遍历?【C】
    A forEach
    B for
    C for…in
    D for…of
  13. Math.floor( -3.5 )结果为?-4
  14. 请阅读下面代码 var num = Math.floor(Math.random()*100); 上述代码中num的取值范围是?0-99
  15. JS获取数组有多少个值?length
  16. var arr = [5,3,2,4]; var res = arr.splice(0); console.log(res) 结果是?5,3,2,4
  17. 判断一个值在某个数组中是否存在,返回这个值在数组中的位置的方法是?indexOf()如果存在返回下标,如果不存在返回-1
  18. var arr = [1,2,3,4]; arr.push(1,[1,2,3],2); alert(arr.length)7
  19. var arr = [1,2,3]; var brr = arr; brr[0]=“lemon” 请问arr、brr的值为?lemon,2,3
  20. 哪个属性可以获得滚动条已经滚动的垂直距离?
    document.body.scrollTopdocument.documentElement.scrollTop
  21. var bool = true; setTimeout(function(){ bool = false },0); console.log(bool)true
  22. 已知当前的系统时间,var now = new Date(),设置3天后的时间正确写法是?【AC】
    A now.setDate(now.getDate()+3)
    B now.setTime(now.getTime()+3)
    C now.setTime(now.getTime()+31000360024)
    D now.setDate(now.getDate()+3
    1000360024)
  23. 以下返回结果为类数组对象的语句为?【BD】
    A document.getElementById()
    B document.getElementsByClassName()
    C document.querySelector ()
    D document.querySelectorAll()
  24. 在Javascript中,关于window对象描述不正确的是?【D】
    A window.history属性是指有关客户访问过的URL信息
    B window.confirm( )方法显示一个带有提示信息和确认及取消按钮的警示框
    C window.prompt( )方法用于显示可提示用户进行输入的对话框
    D window.onload 事件会在窗口或框架被调整大小时发生。
  25. 节点的nodeType值是什么,代表着是元素节点?1
  26. 添加节点的方法?
    appendChild()
    insertBefore()
  27. 两个字符大小比较规则是什么?ASCII
  28. 以下代码执行后,哪个结果是正确的 var str = “hello world”; console.log( str. substring(2,7) )llo w
  29. 下面哪些方式可以将div的文字设置为红色?【BC】
    A div.color = “red”
    B div.style.color =“red”
    C div.style.cssText=“color:red”
    D div.cssText=“red”
  30. 可以通过哪种方式改变元素obox的样式 或 class名?【AB】
    A obox.style.color=“red”
    B obox.className=“active”
    C obox.color=“red”
    D obox.style.className=“active”
  31. var arr = [how,are,you]; arr.reverse(); alert(arr)【B】
    A how,are,you
    B you,are,how
    C h,o,w,a,r,e,y,o,u
    D u,o,y,e,r,a,w,o,h
  32. 日期对象设置年月日的方法有?【AD】
    A setFullYear
    B setYear
    C setDay
    D setDate
  33. var str = “abcdfghi”; 下面哪些方式可以实现截取"bcd"【AB】
    A str.substr(1,3)
    B str.substring(1,4)
    C str.substring(1,3)
    D str.substr(1,4)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值