function sendSNS(media) {

switch(media) {

case "tw":

sendUrl = "http://twitter.com/share?url="+$("#url").val()+"&count=none&text="+$("#title").val();

window.open(sendUrl,'트위터공유하기','width=600, height=400, toolbar=no, status=no,scrollbars=yes, resizable=no, top=0, left=0');

break;

case "fa":

sendUrl = "http://www.facebook.com/sharer.php?s=100&p[url]="+$("#url").val()+"&p[title]="+$("#title").val(); 

window.open(sendUrl,'페이스북공유하기', 'width=1024, height=600, toolbar=no, status=no,scrollbars=yes, resizable=no, top=0, left=0');

break; 

}


자바스크립트에서 replaceAll 은 없다. 

정규식을 이용하여 대상 스트링에서 모든 부분을 수정해줄 수 있다. 

ex) 

str.replace("#",""); -> #를 공백으로 변경한다. 

하지만 첫번째 # 만 공백으로 변경하고 나머지는 변경이 되지 않는다. 

str.replace(/#/gi, ""); -> #를 감싼 따옴표를 슬래시로 대체하고 뒤에 gi 를 붙이면 

replaceAll 과 같은 결과를 볼 수 있다.

1. jQuery로 선택된 값 읽기

 

$("#selectBox option:selected").val();

$("select[name=name]").val();

 

2. jQuery로 선택된 내용 읽기

 

$("#selectBox option:selected").text();

 

3. 선택된 위치

 

var index = $("#test option").index($("#test option:selected"));

 

4. Addoptions to the end of a select

 

$("#selectBox").append("<option value='1'>Apples</option>");

$("#selectBox").append("<option value='2'>After Apples</option>");

 

5. Addoptions to the start of a select

 

$("#selectBox").prepend("<option value='0'>Before Apples</option>");

 

6. Replaceall the options with new options

 

$("#selectBox").html("<option value='1'>Some oranges</option><option value='2'>MoreOranges</option>");

 

7. Replaceitems at a certain index

 

$("#selectBox option:eq(1)").replaceWith("<option value='2'>Someapples</option>");

$("#selectBox option:eq(2)").replaceWith("<option value='3'>Somebananas</option>");

 

8. 지정된 index값으로 select 하기

 

$("#selectBox option:eq(2)").attr("selected", "selected");

 

9. text 값으로 select 하기

 

$("#selectBox").val("Someoranges").attr("selected", "selected");

 

10. value값으로 select 하기

 

$("#selectBox").val("2");

 

11. 지정된 인덱스값의 item 삭제

 

$("#selectBox option:eq(0)").remove();

 

12. 첫번째 item 삭제

 

$("#selectBox option:first").remove();

 

13. 마지막 item 삭제

 

$("#selectBox option:last").remove();

 

14. 선택된 옵션의 text 구하기

 

alert(!$("#selectBox option:selected").text());

 

15. 선택된 옵션의 value 구하기

 

alert(!$("#selectBox option:selected").val());

 

16. 선택된 옵션 index 구하기

 

alert(!$("#selectBox option").index($("#selectBox option:selected")));

 

17. SelecBox 아이템 갯수 구하기

 

alert(!$("#selectBox option").size());

 

18. 선택된 옵션 앞의 아이템 갯수

 

alert(!$("#selectBox option:selected").prevAl!l().size());

 

19. 선택된 옵션 후의 아이템 갯수

 

alert(!$("#selectBox option:selected").nextAll().size());

 

20. Insertan item in after a particular position

 

$("#selectBox option:eq(0)").after("<option value='4'>Somepears</option>");

 

21. Insertan item in before a particular position

 

$("#selectBox option:eq(3)").before("<option value='5'>Someapricots</option>");

 

22. Gettingvalues when item is selected

 

$("#selectBox").change(function(){

           alert(!$(this).val());

           alert(!$(this).children("option:selected").text());

});

+ Recent posts