使用jQuery恢复到窗体上的默认选项

时间:2012-01-11 12:41:25

标签: jquery forms option

我需要恢复magento搜索结果页面上表单上的默认选项。

我使用了以下Jquery,它在firefox上运行正常。问题出在IE上。

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery('#form-validate-small option:selected').removeAttr('selected');
});
</script>

希望有意义

感谢

3 个答案:

答案 0 :(得分:0)

尝试jQuery('#form-validate-small option:selected')。attr('selected',false);


编辑

我在IE7上尝试过,发现它不起作用 应该使用适当的财产 尝试,

jQuery('#form-validate-small option:selected').attr('checked', false);

答案 1 :(得分:0)

如果我理解正确,您不想使用具有

的选项
selected='selected' 

如果是这样,请使用这段jQuery:

$('#foo').val(0);

答案 2 :(得分:0)

这应该有效:

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery('#form-validate-small option:selected').removeAttr('selected');
    jQuery('#form-validate-small option:first-child').attr('selected', 'selected');
});
</script>

了解http://jsfiddle.net/VDw7B/3/