开发者

is it some bug in firefox or jquery or i doing something wrong? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I want to change hidden input value on div click, so i do following:

$('#gallery').click(function(){
        if ($('input[name=isgallery]').attr('value') == '0') {
            $('input[name=isgallery]').attr('value', '1')
        }
        else {
            $('input[name=isgallery]').attr('value', '0')
        }
        $('#filterform').attr('action',$('#filterform').attr('act'));
        aler开发者_如何学编程t('ok');
        $('#filterform').submit();
    }
    );

when it equals 0 i change it to 1 and otherwise but it did not work and following code works:

$('#gallery').click(function(){
        if ($('input[name=isgallery]').attr('value') == '0') {
            $('input[name=isgallery]').attr('value', '0')
        }
        else {
            $('input[name=isgallery]').attr('value', '1')
        }
        $('#filterform').attr('action',$('#filterform').attr('act'));
        alert('ok');
        $('#filterform').submit();
    }
    );

and also, when i delete the function at all it still works and form submits

maybe i have one more handler for this div, but i can't find one

you can check it on http://www.4block.org/en/museum/posters and click "gallery view" on top-right


This should work a little better cross-browser, plus less DOM traversing to find elements :)

$('#gallery').click(function(){
  $('input[name=isgallery]').each(function() {
    $(this).val($(this).val() == '0' ? '1' : '0');
  });
  $('#filterform').attr('action',$('#filterform').attr('act')).submit();
});


Try using the val() function to change an input's value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜