2013-05-21 7 views
0

문자열의 첫 번째 문자 인 숫자를 나머지 문자열과 구분하려고합니다. 예를 들어 선택할 1 옵션은 선택할 수있는 1 옵션이어야합니다. 문자열에서 첫 번째 문자를 구분합니다.

이 선택 목록을 동적으로 나는 다음과 같은 방법으로 그것을 할 것

<select> 
    <option>1options to select</option> 
    <option>2anything can be here</option> 
    <option>3anything can be here</option> 
    <option>5anything can be here</option> 
</select> 

$(".custom-ordered-list select option").each(function() { 

    //i think i need to loop through but not sure what to do next.      
}); 
+0

은 9999 옵션을 선택할 수 있습니까? 또는 '9999 무엇인가'? –

+0

네, 그럴 수 있습니다 .. – gables20

답변

4

생성되어 있습니다 :

$(".custom-ordered-list select option").text(function(i, text) { 
    return text.replace(/^\d+/, "$& "); 
}); 

DEMO :http://jsfiddle.net/63h7T/

+0

+1이 방법 클리너입니다 .. – techfoobar

+0

이것은 완벽하게 일을했다. – gables20

+1

@roasted 질문 아래의 주석을 읽으십시오. – VisioN

1

당신은 할 수 있습니다 :

$(".custom-ordered-list select option").each(function() { 
    $(this).text($(this).text().replace(/^(\d+)(.+)$/, '$1 $2')); 
}); 
+0

이것은 또한 완벽하게 작동했습니다. – gables20

관련 문제