老师,页面无反应!

来源:1-4 基本选择器

CodeMz

2020-03-06 09:43:50

<!DOCTYPE html >

<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery实验室</title>

<style>
.myclass {
	font-style: italic;
	color: darkblue;
}
/* 高亮css类 */
.highlight {
	color: red;
	font-size: 30px;
	background: lightblue;
}
</style>

</head>

<body>
	<div class="section">
		<h2>jQuery选择器实验室</h2>
		<input style="height: 24px" id="txtSelector" />
		<button id="btnSelect" style="height: 30px">选择</button>
		<hr />
		<div>
			<p id="welcome">欢迎来到选择器实验室</p>
			<ul>
				<li>搜索引擎:<a href="http://www.baidu.com">百度</a> <span> <a
						style="color: darkgreen" href="http://www.so.com">360</a>
				</span>
				</li>
				<li>电子邮箱:<a href="http://mail.163.com">网易邮箱</a> <span> <a
						style="color: darkgreen" href="http://mail.qq.com">QQ邮箱</a>
				</span>
				</li>
				<li>中国名校:<a href="http://www.tsinghua.edu.cn">清华大学</a> <span>
						<a style="color: darkgreen" href="https://www.pku.edu.cn/">北京大学</a>
				</span>
				</li>
			</ul>

			<span class="myclass ">我是拥有myclass类的span标签</span>

			<p class="myclass">我是拥有myclass的p标签</p>
			<form id="info" action="#" method="get">
				<div>
					用户名:<input type="text" name="uname" value="admin" /> 密码:<input
						type="password" name="upsd" value="123456" />
				</div>
				<div>
					婚姻状况: <select id="marital_status">
						<option value="1">未婚</option>
						<option value="2">已婚</option>
						<option value="3">离异</option>
						<option value="4">丧偶</option>
					</select>
				</div>
				<div class="left clear-left">
					<input type="submit" value="提交" /> <input type="reset" value="重置" />
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	document.getElementById("btnSelect").onclick = function() {
		$("#marital_status").addClass("highlight");
		var selector = document.getElementById("txtSelector").value;
		$("*").removeClass("highlight");
		$(selector).addClass("highlight");
	}
</script>
	
</body>
</html>

老师帮忙看一下,为什么,script里面的代码不生效,我用alter()输入字符浏览器查看也没有弹窗,页面没有反应,麻烦看下谢谢

写回答

1回答

好帮手慕小班

2020-03-06

同学你好,测试同学的代码,并没有导入jquery库,例如:

http://img.mukewang.com/climg/5e61d03a09765bb507120142.jpg

如上修改后,同学再来尝试一下,这里老师导入jquery后,可以正常加载了。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

0
hodeMz
h 可以了,谢谢!
h020-03-06
共1条回复

0 学习 · 9666 问题

查看课程