我对我的代码做了最后一刻的更改,并意识到 jQuery 在 IE 和 Chrome 中不起作用,但在 FF 中运行良好。我设法将一些现有的 jQuery 更改为 js,并且它在所有浏览器中都可以正常工作,但是,下面的 jQuery 在 IE 和 Chrome 中无法工作。
我希望我不需要将此代码更改为纯 JS,所以希望有一个解决方法,您知道我做错了什么吗?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#address').change(function() {
$('#mycheckboxdiv').toggle();
});
$('#name').click(function() {
alert("well hello there.");
});
$('#school').keyup(function(e) {
if (e.which == 9)
alert("great school");
});
});
</script>
</head>
<body>
<form name="myform" method="post" action="myform.php" id="myform">
<table>
<tr>
<td><b>Name:</b></td>
<td><input name="name" id="name" value="" type="text" size="20" maxlength="20"/></td>
</tr>
<tr>
<td valign="top">
<input name="address" value="NO" type="checkbox"> NO<br>
<input name="address" id="address" value="YES" type="checkbox"> YES</td>
</tr>
<tr id="mycheckboxdiv" style="display:none">
<td colspan="2"></td>
</tr>
</table>
</form>
</body>
</html>
最佳答案
大多数浏览器依赖type
,不是language
触发 JavaScript 解释器。所以如果你输入 <script type="text/javascript"></script>
,您甚至不需要指定 language
。 language
该属性已被弃用一段时间了。
参见this问题。
用这个代替你当前拥有的:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
此外,对于 HTTPS
问题,请使用以下内容:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
或者您可以指定 HTTPS
直接:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
关于javascript - jquery 不能在 IE、Chrome 中工作,可以在 FF 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16148032/