我有两个不同的 jquery 脚本,它们都可以单独工作,但是当我尝试在同一页面上组合它们时,它们会崩溃。我注意到他们调用不同版本的 jquery,但如果我尝试使用其中一个版本,它就会破坏其中一个功能。有人帮助我知道为什么吗?
第一个脚本:
<head>
<link rel="stylesheet"href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="ajax.js"language="javascript"type="text/javascript"></script>
<script>
$(function() {
var availableTags = [
"Abel Law Offices",
"Abigail Rivamonte, Attorney at Law",
"Abrams & Heyn"
];
$( "#tags").autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<input type="text" id="tags" name="tags" >
</body>
</html>
第二个脚本:
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
$("#checkbox_1").change(function () {
$("#tags").attr("disabled", $(this).attr("checked"));
});
});
</script>
这里有什么问题吗?预先感谢您。
我想要的是一个建议字段框,以及一个单击时禁用建议字段框的复选框。我以前曾单独完成过这两个操作,所以我想我可以简单地使用两者......但可惜。
最佳答案
仅使用 jQuery 1.9 或最新分支并尝试以下行:
$("#tags").attr("disabled", $(this).prop("checked"));
而不是
$("#tags").attr("disabled", $(this).attr("checked"));
.attr() 函数始终为您提供最初设置的属性。这是您正在寻找的 .prop() 。这将为您提供复选框的当前值。
不要同时包含两个不同版本的 jQuery。
关于jquery - jquery 与不同脚本的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18089002/