更新jQuery破坏了我的显示/隐藏
我有一个更改电话号码的脚本,但是这个脚本只适用于jQuery1.6.4——一旦我更新到1.7.2,它就停止工作了。我错过了什么更新jQuery破坏了我的显示/隐藏,jquery,Jquery,我有一个更改电话号码的脚本,但是这个脚本只适用于jQuery1.6.4——一旦我更新到1.7.2,它就停止工作了。我错过了什么 <script type="text/javascript">// <![CDATA[ $('a#reno-trigger').click(function(){ $('#toggle-lv').show(); $('#toggle-reno').hide(); }); $('a#lv-trigger').click(function(){ $('
<script type="text/javascript">// <![CDATA[
$('a#reno-trigger').click(function(){
$('#toggle-lv').show();
$('#toggle-reno').hide();
});
$('a#lv-trigger').click(function(){
$('#toggle-reno').show();
$('#toggle-lv').hide();
});
// ]]></script>
//
HTML:
拉斯维加斯|
702.555.5555
|雷诺
555.555.5555
我将删除这一行,脚本将不再工作:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
我还拿出了CDATA
我的wordpress正在加载1.7.2的本地版本
<script type='text/javascript' src='http://xxx.com/wp-includes/js/jquery/jquery.js?ver=1.7.2'></script>
我补充说:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
它再次工作,但我加载了两个jQuery,这似乎很奇怪
我想这毕竟不是jQuery的更新
document.ready现已实施:
<script type="text/javascript">
$(document).ready(
$('a#reno-trigger').click(function(){
$('#toggle-lv').show();
$('#toggle-reno').hide();
});
$('a#lv-trigger').click(function(){
$('#toggle-reno').show();
$('#toggle-lv').hide();
});
);
</script>
$(文件)。准备好了吗(
$('a#reno触发器')。单击(函数(){
$(“#切换lv”).show();
$('#toggle reno').hide();
});
$('a#lv触发器')。单击(函数(){
$('#toggle reno').show();
$(“#切换lv”).hide();
});
);
那个脚本在一段时间内不起作用,我一定是把文件搞砸了。。。我现在已经把它放回去了。试试这个:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('a#reno-trigger').click(function(){
$('#toggle-lv').show();
$('#toggle-reno').hide();
});
$('a#lv-trigger').click(function(){
$('#toggle-reno').show();
$('#toggle-lv').hide();
});
});
</script>
$(函数(){
$('a#reno触发器')。单击(函数(){
$(“#切换lv”).show();
$('#toggle reno').hide();
});
$('a#lv触发器')。单击(函数(){
$('#toggle reno').show();
$(“#切换lv”).hide();
});
});
这是可行的,我不知道为什么。但它是有效的:)
//
有JavaScript错误吗?我们可以查看任何HTML吗?不确定为什么它取决于版本,但您应该将此代码放在$(document).ready()
函数中。通过更新到1.7.2Get,您的代码中没有任何内容会被破坏,请删除//]>
内容。您不需要两者兼而有之。去掉一个。这很有效,但只是因为我必须包含第二个jQuery。(它也可以与原始函数一起使用。)在加载任何其他依赖项之前,请确保正在加载jQuery
。查看页面源代码时,它看起来是有序的。这与我的答案不一样吗?它工作的原因是因为将其包装在jQuery(document).ready(函数($){…})中代码>(也可以写为$(function(){…});
)在执行脚本之前等待文档完全加载(DOM准备就绪)。我粘贴了您的解决方案,但它不起作用,但由于您是唯一发布实际答案的人,我可以接受您的答案,因为它引导我走上正确的道路。。。。好吧,我把你的建议和巴尔马的建议结合起来,加上了我自己的风格!:P
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('a#reno-trigger').click(function(){
$('#toggle-lv').show();
$('#toggle-reno').hide();
});
$('a#lv-trigger').click(function(){
$('#toggle-reno').show();
$('#toggle-lv').hide();
});
});
</script>
<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function($){
$('a#reno-trigger').click(function(){
$('#toggle-lv').show();
$('#toggle-reno').hide();
});
$('a#lv-trigger').click(function(){
$('#toggle-reno').show();
$('#toggle-lv').hide();
});
});
// ]]></script>