2012-01-11 27 views
1

我需要恢復到magento上的搜索結果頁上的表單上的默認選項。使用jQuery恢復爲表單上的默認選項

我已經使用了下面的jquery,它在firefox上正常工作。問題是與IE。

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

希望是有道理的

感謝

回答

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/

+0

謝謝傑弗裏。它現在完美的工作:) – 2012-01-11 13:03:35

0

嘗試的jQuery( '#表單驗證小選項:選擇')。ATTR( '選擇',虛假);


編輯

我已經試過在IE7,發現這是行不通的。
應該使用適當的屬性。
嘗試,

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

感謝您的快速響應,它導致同樣的問題,在Firefox中工作正常,但不在IE中。 – 2012-01-11 12:52:28

+0

@JamesDickinson我檢查了它並編輯了我的答案。在ie7上測試。 – Sang 2012-01-11 13:03:04

0

如果我理解正確的話,你不希望使用具有

selected='selected' 

如果是這樣的選項,用這塊的jQuery:

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

你能給我完整的腳本與我給上面的東西嗎?它似乎仍然不能在IE – 2012-01-11 12:59:56