问题描述
已经在小提琴中尝试并测试了代码,目的是在顶部的下拉菜单中有1时隐藏第二列,这可以在小提琴上工作,但在网页上没有任何变化。任何想法。
测试网页位于实况网站上,位于:
您的jQuery代码在元素位于DOM之前执行。将其包装在处理程序中以解决此问题:
$(function(){
//您的代码在这里
$(#selectList)。change(function(){
if($(this).val()==1){
$(。showMe)。hide();
}
else {
$( .showMe)。show();
}
});
});
你的小提琴有一个onLoad包装(页面的左上角),它自动将你的代码包装在 window.onload
函数。
window.onload
作品但是当你有一个包含图片和其他资源的大页面时,它比DOM准备好的处理程序需要的时间要长得多。
Have tried and tested code in fiddle, the aim is to hide second column when there is a 1 in the dropdown at the top, this works on fiddle, but nothing changes on webpage. Any ideas.
Testing webpage is on a live site, located here: http://www.specialfinance.co.uk/introducers/submit-an-enquiry/secured-loans2.html
Your jQuery code is executing before the elements are in the DOM. Wrap it inside a DOM Ready handler to fix that:
$(function() {
//your code here
$("#selectList").change(function() {
if ($(this).val() == "1") {
$(".showMe").hide();
}
else {
$(".showMe").show();
}
});
});
Your fiddle has an onLoad wrapper (top-left of the page) which automatically wraps your code inside an window.onload
function.
window.onload
works too but it takes considerably longer than a DOM ready handler to kick in when you have a large page with images and other resources.
这篇关于代码在小提琴中工作,但不在网页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!