简体   繁体   English

jQuery .show()和.hide()甚至.css({“ display”:“ none”})); 在Firefox中无法工作?

[英]Jquery .show() and .hide() or even .css({“display”:“none”}); not working in firefox?

For some odd reason the part where objects are shown and hidden in my script doesn't seem to be working. 出于某种奇怪的原因,脚本中显示和隐藏对象的部分似乎不起作用。 I'm not sure if its the fact firefox doesn't like that or whether its the function-based code I have (to save duplicating lines of code)? 我不确定firefox是否不喜欢它,或者我是否拥有基于函数的代码(以节省重复的代码行)?

There is a working example here and the javascript is here 有一个工作示例这里和JavaScript是这里

** Here is the jquery ** **这是jQuery **

$(document).ready(function(){

totUpPrices();
checkBedType();
checkHeadboardOption();

$('.bedtype_price').click(function()
{
    checkBedType(); 
});

$('.headboard_option').click(function()
{
    checkHeadboardOption();
});

$('#bed-floater').scrollFollow({ offset:10 });
$('.texture').click(function()
{

    $('.texture').removeClass("checked");
    $('.texture').children("input").attr("checked","");

    $(this).addClass("checked");
    $(this).children("input").attr("checked","checked");

});

$('.pricechanger_auto').change(function()
{
    totUpPrices();
});

$('.bed-width-single').change(function()
{
    if($(this).val()=="2' 6\"" || $(this).val()=="3'")
    {
        $('.pocketmatic-mattress').attr("disabled","");
    }
    else
    {
        $('.pocketmatic-mattress').attr("disabled","disabled");
        if($('.pocketmatic-mattress').parent("select").val()=="Pocketmatic")
        {
            $('.pocketmatic-mattress').parent("select").children("option[value='']").attr("selected","selected");
        }
    }
});

$('.bed-width-twin').change(function()
{
    if($(this).val()=="4' 6\"" || $(this).val()=="6'")
    {
        $('.pocketmatic-mattress').attr("disabled","");
    }
    else
    {
        $('.pocketmatic-mattress').attr("disabled","disabled");
        if($('.pocketmatic-mattress').parent("select").val()=="Pocketmatic")
        {
            $('.pocketmatic-mattress').parent("select").children("option[value='']").attr("selected","selected");
        }
    }
});

function totUpPrices()
{

    var totalprice = 0;

    // Check Type of bed prices
    var objs = $('.bedtype_price');
    $.each(objs, function(index, value) {

        if($(value).attr("checked"))
        {
            totalprice = totalprice + parseInt($(value).attr("cost"));
        }

    });

    // Check Delivery Options
    var objs = $('.deliveryoptions_price');
    $.each(objs, function(index, value) {

        if($(value).attr("checked"))
        {
            totalprice = totalprice + parseInt($(value).attr("cost"));
        }

    });

    // Check Dropdown Prices
    var objs = $('.select_price');
    $.each(objs, function(index, value) {

        newvalue = $(value).attr("value");
        $.each($(value).children("option"), function(i, l){
            if($(this).attr("value")==newvalue)
            {
                totalprice = totalprice + parseInt($(this).attr("cost"));
            }

        });

    });
    $('#totalincvat').text(totalprice);
}

function checkBedType()
{
    var objs = $('.bedtype_price');
    var checkedType = '';
    $.each(objs, function(index, value) {

        if($(value).attr("checked"))
        {
            checkedType = $(value).val();
        }

    });
    if(checkedType == "Single Bed")
    {
        $('.show_with_single').show();
        $('.show_with_twin').hide();
        $('.changeOnTwin').text("Would you like a headboard?");
    }
    else
    {
        $('.show_with_twin').show();
        $('.show_with_single').hide();
        $('.changeOnTwin').text("Would you like headboards?");
    }
}

function checkHeadboardOption()
{
    var objs = $('.headboard_option');
    var checkedType = '';
    $.each(objs, function(index, value) {

        if($(value).attr("checked"))
        {
            checkedType = $(value).val();
        }

    });
    if(checkedType == "Yes")
    {
        $('.headboard-options').show();
    }
    else
    {
        $('.headboard-options').hide();
    }
}

});

All help appreciated 所有帮助表示赞赏

Your HTML does not validate. 您的HTML无效。 See here, 看这里,

http://validator.w3.org/check?uri=http%3A%2F%2Fbed-adjustable.co.uk%2Fbuild-a-bed%2F&charset=%28detect+automatically%29&doctype=Inline&group=0 http://validator.w3.org/check?uri=http%3A%2F%2Fbed-adjustable.co.uk%2Fbuild-a-bed%2F&charset=%28detect+automatically%29&doctype=Inline&group=0

The very first line of your html is already invalid. html的第一行已经无效。

Sorry your first line is ok, I didnt know that was HTML5, though it is pretty early to do HTML5. 抱歉,您的第一行还可以,我不知道那是HTML5,尽管现在做HTML5还为时过早。

我没有关注您的链接(请参阅我对您问题的评论),但是从根本上讲,Firefox在jQuery的showhide或设置display: none方面没有问题display: none CSS中display: none ,所以这是一个代码问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM