2010-12-18 3 views
1

나는이 내가 지금 무엇을 가지고 드롭 다운 목록을 정렬되지 않은 목록으로 바꾸십시오. 자바 스크립트는 방법

<div id="edit-country-wrapper"> 
    <select id="edit-country" class="form-select" name="country"> 
    <option selected="selected" value="all">All</option> 
    <option value="canada">Canada</option> 
    <option value="usa">USA</option> 
    </select> 
</div> 

을 그리고

<div id="edit-country-wrapper"> 
    <ul id="edit-country" class="form-select" name="country"> 
    <li><a class="selected" href="/all">All</a></li> 
    <li><a class="" href="/canada">Canada</a></li> 
    <li><a class="" href="/usa">USA</a></li> 
    </ul> 
</div> 

로 변경하고 싶습니다.

$(document).ready(function() { 
    $('#edit-country-wrapper select').each(function() { 
     var $select = $('<div id="location-select" />'); 
     $(this).find('option').each(function() { 
      var $option = $('<a />'); 
      $option.attr({ 
       href: '?country=' +$(this).attr('value'), 
       id: 'location-' + $(this).attr('value'), 
       class: $(this).attr('selected'), 
       html: $(this).html() 
      }); 
      $select.append($option); 
     }); 

     $(this).replaceWith($select); 
    }); 
}); 

정렬되지 않은 목록으로 드롭 다운 목록을 대체하려고합니다. 내가 FF & 크롬에서 일하고 있지만 IE에는 없다. 도와주세요!!

+0

? 오류가 발생 했습니까? HTML이 잘 생성 되었습니까? – alex

+0

IE는 드롭 다운을 목록으로 변환하지 않지만 FF 및 Chrome은 목록으로 변환합니다. – canintex

답변

1

attr과 같은 HTML을 설정하는 데 사용할 수 없다고 생각합니다. (thinkhtml이라는 링크에 새로운 속성을 만듭니다).

는 너무 오래

var $option = $('<a />', { 
       href: '?country=' +$(this).attr('value'), 
       id: 'location-' + $(this).attr('value'), 
       class: $(this).attr('selected'), 
       html: $(this).html() 
      }); 

... 당신이 사용하는 같은 것을 대체하는 시도 jQuery를> = 1.4 IE에서 작동하지 않습니다 무엇

+0

jQuery를 사용하고 있습니다. 1.2.6 – canintex

+0

죄송합니다 ... jQuery 1.3.2 – canintex

+0

@Erik이 경우'html'을 그렇게 설정할 수 없습니다. 별도의 메소드 인'html()'을 묶어서 첫 번째 인자는 HTML이다. – alex

1
$option.attr({ 
    href: '?country=' +$(this).attr('value'), 
    id: 'location-' + $(this).attr('value'), 
    class: $(this).attr('selected'), 
}).html($(this).html()); 
관련 문제