2013-01-02 42 views
0

所選的單選按鈕將顯示其對應的下拉框。顯示內容的替代方法

例如,在選定的單選按鈕「安大略省」上,將出現一個包含匹配城市的下拉框。

我有上述示例下列工作的代碼:

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#searchForm input:radio").change(function() { 

     var buttonPressed = $('[name="Region"]:radio:checked').val(); 
     var cityElmntBox = document.getElementById("dispalyCityBox"); 

     if(buttonPressed == 'Ontario'){ 
      cityElmntBox.style.display='block'; 
     } else { 
      cityElmntBox.style.display='none'; 
     } 

    }); 
}); 
</script> 

代替突然效果(display='block'),我想使用所選元素slideDown()方法。

所以我代替:

cityElmntBox.style.display='block'; 

有:

cityElmntBox.slideDown(500); 

但是,這並不工作...,請有人可以幫助我得到它的工作?

+0

'dispalyCityBox' - >確定你沒有打字錯誤嗎?無論如何,在處理DOM時不要混合使用jQuery和原始js,使用'$()'選擇器! – moonwave99

回答

1

改爲嘗試$('#dispalyCityBox').slideDown(500)

通過使用cityElmntBox.slideDown(500);您試圖在非jQuery對象上使用jQuery方法。

+1

工作!非常感謝您的幫助,快速響應和專業性。 – blsn

+0

不客氣。樂意效勞。 – j08691

2

把它包在jQuery的:

$(cityElmntBox).slideDown(500); 

還可以簡化var語句這樣,你不會有把它放在一個包裝:

var cityElmntBox = $("#dispalyCityBox"); 
2

使用$('#dispalyCityBox'),而不是document.getElementById("dispalyCityBox")