每当为子输入元素触发keydown事件时,我正在编写一个jquery脚本来更改父div的颜色,但代码似乎没有运行.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").keydown(function(){
$("#div").css("background-color","teal");
});
});
</script>
</head>
<body>
<div id="div">
<input type="text">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
你忘了你的jquery链接中的'http'(假设你file://用来访问该文件),改变
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
至
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
编辑:
当准备好去服务器时,将其更改回来//ajax.googleapis.com/...以避免@Femaref提到的http/https问题