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.
精彩评论