2013-02-21 3 views
2

Coffeescript를 통해 국가 드롭 다운이 "캐나다"또는 "미국"인 경우 주 /도 필드를 표시하려고합니다.커피점 드롭 다운 값

지금까지 내가 가진 (그러나 복잡한 통해 보인다) 당신은, 그러나

selected = $('#order_shipping_address_attributes_country option:selected').text() 

을 할 수 http://api.jquery.com/selected-selector/에 따라 상황이 더 나은와

selected = $('#order_shipping_address_attributes_country option') 
      .filter(':selected').text() 

답변

4

을 수행합니다

canada = "Canada" 
usa = "United States" 
$('#order_shipping_address_attributes_country').change -> 
    selected = $('#order_shipping_address_attributes_country :value').text() 
    $('#shipping_province').show() if selected is canada 
4

다음 작품 :

$('#order_shipping_address_attributes_country').change -> 
    selected = $('#order_shipping_address_attributes_country option').filter(':selected').text() 
    if selected is "Canada" or selected is "United States" 
    $('#shipping_province').show() 
    else 
    $('#shipping_province').hide() 
+0

jQuery에 따라 권장되는 방법을 지적 해 주셔서 감사합니다. 나는 그것의 일부를 사용하는 것을 끝내었다. – olimart