반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형
Dynamically insert a new column


처음에 테이블에는 두개의 row 와 세개의 column이 있습니다. 여기에 한개의 컬럼을 더 추가하기를 원합니다.


Inserting dynamic column in a table


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <div id=table class=ui-grid-b>

      <div class=ui-block-a>Element 1.1</div>

      <div class=ui-block-b>Element 1.2</div>

      <div class=ui-block-c id=insert>Element 1.3</div>

      <div class=ui-block-a>Element 2.1</div>

      <div class=ui-block-b>Element 2.2</div>

      <div class=ui-block-c>Element 2.3</div>

    </div>

  </div>

</div>


</body>

</html>


<script>


$("#table").removeClass ("ui-grid-b").addClass ("ui-grid-c");

var html = "<div class=ui-block-d> Element 1.4 </div>";

$("#insert").after (html);


</script>



tistory444_01.html


페이지가 시작할 때 CSS 클래스를 ui-grid-b에서 ui-grid-c로 바꾸도록 해 새로운 컬럼을 가지고 있는 테이블이 되도록 했습니다. 그 다음에 after () method 를 사용해서 insert identifier 에 의해 위치를 정해준 다음 해당 element를 insert 하게 됩니다.


원래 테이블은 두개의 줄과 세개의 컬럼이 있었습니다.



그런데 script 가 한번 돌고 나면 첫번째 줄의 끝에 컬럼이 하나 더 추가됩니다.





반응형

Ajax 로 테이블 삽입하기

2012. 11. 6. 06:55 | Posted by 솔웅


반응형
Insert tables with Ajax



Insert a simple table


Ajax를 통해서 text를 가지고 있는 테이블을 삽입하는 방법을 살펴보죠.

아주 간단하게 구현할 수 있습니다.


Insert a table containing text elements by Ajax


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home div:jqmData(role=content)").append (response);

  }

});   


</script>



Ajax에 의해 call 되는 서버의 action.php file 은 아래와 같습니다.


action.php file


<?
$html = "";
$html .= "<div class=ui-grid-b>";
$html .=   "<div class=ui-block-a>Element 1.1</div>";
$html .=   "<div class=ui-block-b>Element 1.2</div>";
$html .=   "<div class=ui-block-c>Element 1.3</div>";
$html .=   "<div class=ui-block-a>Element 2.1</div>";
$html .=   "<div class=ui-block-b>Element 2.2</div>";
$html .=   "<div class=ui-block-c>Element 2.3</div>";
$html .= "</div>";

echo utf8_encode ($html);
?>


action5.php

tistory443_01.html


페이지를 오픈하면 Ajax 가 server 로 call 해서 테이블을 받아오고 이것을 윈도우에 뿌려줍니다. 약간의 시간이 걸릴 수도 있습니다.





Insert a table with buttons


위의 예제에서 조금 변경을 해 보죠. 서버쪽에서 버튼을 가지고 있는 array 를 return 한다고 가정해 봅시다. 예를들어 OK button 과 Delete button을 건네 받을 겁니다.


Insert a table that contains buttons by Ajax


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  <style type=text/css>

    .ui-btn {

      width : 140px;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home div:jqmData(role=content)").append (response);

    

    $("a").button ();

    $(".ui-grid-a").controlgroup ();

  }

});   


</script>



서버에서 return 되는 <a> links 들이 버튼으로 변경될 겁니다. 이 때 사용하는 메소드는 button () method 입니다. 이 버튼들은 controlgroup () method 로 묶은 후 border 로 둘러싸여질 겁니다. 위에 있는 ui-btn class 에 의해서 버튼들은 같은 width 를 가지게 됩니다.


action.php file


<?
$html = "";
$html .= "<div class=ui-grid-a data-type=horizontal>";
$html .=   "<div class=ui-block-a style=text-align:right>";
$html .=     "<a href=#> OK </a>";
$html .=   "</div>";
$html .=   "<div class=ui-block-b>";
$html .=     "<a href=#> Delete </a>";
$html .=   "</div>";
$html .= "</div>";

echo utf8_encode ($html);
?>


action6.php


tistory443_02.html




반응형


반응형
Turning a HTML element into a jQuery Mobile table


A simple table


jQuery Mobile table  ui-grid-a, ..., ui-grid-d, and u-block-a, ..., ui-block-e 같이 specialized 된 CSS classes 들을 가지고 있는 <div> elements를 사용합니다. 이런 CSS 클래스들은 jQuery Mobile convention에 맞게 테이블을 스타일화 하는 역할을 합니다. 이전 글의 테이블을 firefox 의 firebug로 보면 아래와 같은 HTML code를 보실 수 있습니다.




아직 jQuery Mobile 에 의해서 modify 되지는 않은 상황입니다.



A table of buttons


테이블에 버튼을 추가해 보겠습니다. data-role="controlgroup"data-type="horizontal" attributes 들을 병행해서 사용하시면 됩니다.


Two buttons side by side in the two cells of a table


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<div class=ui-grid-a data-role=controlgroup data-type=horizontal >";

html +=   "<div class=ui-block-a style=text-align:right>";

html +=     "<a href=# data-role=button style=width:140px> OK </a>";

html +=   "</div>";

html +=   "<div class=ui-block-b>";

html +=     "<a href=# data-role=button style=width:140px> Delete </a>";

html +=   "</div>";

html += "</div>";

$("#home div:jqmData(role=content)").append (html);


</script>



tistory441_01.html



jQuery Mobile 에 의해 생성된 HTML 코드 입니다. firefox의 firebug로 본 화면입니다.



data-role="controlgroup" 이 있는 <div> 를  보시면 jQuery Mobile 에 의해 ui-controlgroupui-controgroup-horizontal CSS 클래스 두개가 추가 된 것을 보실 수 있을 겁니다. 그리고 ui-block-a and ui-block-b CSS classes 가 있는 두개의 <div> elements 들이 있구요. 여기에 버튼들이 삽입됩니다.

<a> link에 data-role="button" attribute 가 있기 때문에 button 으로 변환 됩니다.

결론적으로 테이블을 만들기 위해 jQuery Mobile 에 의해 만들어진 HTML 은 그리 많이 변환되지 않았습니다. 버튼 같은 특정 element 들만이 modify 됩니다. table structure 그 자체는 변환되지 않습니다.



A table of buttons (continued)


HTML에 data-role="controlgroup"data-role="button" attributes를 사용하지 않고 같은 결과를 얻어볼까요. 아래 샘플을 실행해 보세요.


Two buttons side by side in the two cells of a table


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<div class=ui-grid-a data-type=horizontal >";

html +=   "<div class=ui-block-a style=text-align:right>";

html +=     "<a href=# style=width:140px> OK </a>";

html +=   "</div>";

html +=   "<div class=ui-block-b>";

html +=     "<a href=# style=width:140px> Delete </a>";

html +=   "</div>";

html += "</div>";

$("#home div:jqmData(role=content)").append (html);


$("a").button ();

$(".ui-grid-a").controlgroup ();


</script>



tistory441_02.html


해당 element들이 버튼으로 변환되고 같이 그룹화 되도록 하기 위해 button ()controlgroup () 메소드들을 사용했습니다.  


jQuery Mobile 에 의해 생성된 화면을 보면 뭔가 2% 부족한 것을 느끼실 겁니다.






두 버튼의 width 가 같지 않죠. HTML 에서는 140px로 지정돼 있는데 말이죠. 그 이유는 button () method 를 call 하면서 그 아이템에 assign 된 CSS 가 disable 됐기 때문입니다. 해결방법은 jQuery Mobile 이 버튼을 세팅하기 위해 사용한 CSS 클래스에 직접 스타일링 하는 방법이 있습니다. (ui-btn class)


Define this CSS class in our HTML page, in the head section of the page:


Definition of the ui-btn class to style the buttons in the page


<style type=text/css>

.ui-btn {

    color : red;

    width : 140px;

  }

</style>

tistory441_03.html


그러면 아래처럼 보일 겁니다.





이제 버튼은 같은 width 를 갖게 되고 또 글자색도 빨간색으로 display 됩니다.


반응형


반응형

테이블 안에서 데이터를 관리하는 것은 주로 jQuery 의 메소드를 사용해서 구현합니다.  jQuery Mobile에 의해 controlgroup () method 가 추가되서 테이블의 다양한 component들에 visual group 을 제공하게 됩니다.


Dynamically create a table

이제 window에 dynamic 하게 table을 생성하려고 합니다. 이 테이블은 두개의 row와 세개의 column을 가지게 될 겁니다. 이것을 구현하기 위해 ui-grid-b class 가 있는 <div> element 를 생성합니다. 그리고 그 <div> 안에 ui-block-a, ui-block-b and ui-block-c CSS classes를 가지고 있는  <div> elements 들을 넣습니다.


Dynamic creation of table (2 rows and 3 columns)


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<div class=ui-grid-b>";

html +=   "<div class=ui-block-a>Element 1.1</div>";

html +=   "<div class=ui-block-b>Element 1.2</div>";

html +=   "<div class=ui-block-c>Element 1.3</div>";

html +=   "<div class=ui-block-a>Element 2.1</div>";

html +=   "<div class=ui-block-b>Element 2.2</div>";

html +=   "<div class=ui-block-c>Element 2.3</div>";

html += "</div>";

$("#home div:jqmData(role=content)").append (html);


</script>


tistory440_01.html





반응형


반응형

jQuery Conference Asia 2012



벌써 11월 이군요.

여기는 허리케인 Sandy 가 지나간 뒤에 아주 많은 피해가 보도되고 있네요.


지금 사는 로드아일랜드 지역은 다행히 거의 피해가 없지만 몇달 전까지 살던 뉴저지 Bergen County 지역에 피해가 아주 심한 것 같습니다.


거기 계신 한인분들 모두 별 탈 없으셨으면 합니다.


이제 11일 남았네요.

jQuery Conference Asia 2012  행사가 11월 12일에 하니까요.


미국에서 프로젝트 진행하면서 회의 때 이곳 친구들이 알려주는 이런 저런 정보와 기술들을 배우는게 아주 재밌습니다.


그리고 그런 정보와 기술들을 최대한 이 블로그에 정리를 해서 되도록 많은 분들과 공유를 하려고 노력하고 있습니다.


이번에 인크로스사에서 미국의 유명한 분들을 초대해서 최신기술과 전망에 대한 콘퍼런스를 진행한다고 하니 여건되시는 분들 많은 참여 추천 드립니다.


일자는 2012년 11월 12일 08:30~18시까지이고 장소는 서울 르네상스 호텔 3층 다이아몬드 홀 입니다.


참가 등록은 www.jqueryasia.com 으로 하시면 되구요.


감사하게도 인크로스사에서 저희 블로그 이용자 분들 중 한분께 초청장을 협찬하시기로 하셨습니다.


필요하신 분은 제게 이메일(douggy.park@yahoo.com) 을 주시면 추첨해서 한분께 초청장을 드리겠습니다.


자세한 사항은 여기 를 참조해 주세요.


아래는 자세한 행사 내용 입니다.

join_auth.html










반응형

버튼 관련 예제 파일 들

2012. 10. 31. 05:46 | Posted by 솔웅


반응형
Examples of manipulation of buttons



Managing a two-state button (pressed / not pressed)


이전 예제에서 버튼이 클릭됐을 때 어떤 동작을 하도록 했었습니다. 이 버튼의 상태 (pressed / not pressed)를 관리하기 위해 <a> element에 ui-btn-active CSS class 를 사용할 수 있습니다.


Managing a two-state button


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  

  <style type=text/css>

    .ui-btn-inner {

      padding : 25px;

      background-color : black;

    }

    .ui-btn-text {

      font-size : 25px;

      color : white;

    }

    .ui-btn-active {

      font-style : italic;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <a id=btn data-role=button href=#> Click here </a>

  </div>

</div>


</body>

</html>


<script>


$("#btn").bind ("click", function (event)

{

  $(this).toggleClass ("ui-btn-active");

});


</script>

tistory435_01.html



이 소스는 버튼이 클릭되면
ui-btn-active class 를 활성화/비활성화 하는 작업을 jQuery 의 toggleClass () method 를 사용해서 구현했습니다.


Dynamically change the text and the button icon


단순히 글자 모양을 바꾼느 것 보다 클릭함에 따라서 글자 자체와 버튼의 아이콘도 바꾸는 것을 한번 해 보죠.


버튼 ON, OFF 두가지 상태가 있고 버튼이 ON 인 상태에서는 아이콘이 오른쪽에 나타나고 OFF 인 상태에서는 아이콘이 없어지도록 하겠습니다.


Volume management ON or OFF


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <a id=btn data-role=button href=# data-icon=check 

       data-iconpos=right selected=true> Volume ON </a>

  </div>

</div>


</body>

</html>


<script>


$("#btn").attr ("select", "true");


$("#btn").bind ("click", function (event)

{

  var selected = $(this).attr ("select");

  if (selected == "true")

  {

    $(this).attr ("select", "false");

    $(this).find (".ui-icon").hide ();

    $(this).find (".ui-btn-text").text ("Volume OFF");

  }

  else

  {

    $(this).attr ("select", "true");

    $(this).find (".ui-icon").show ();

    $(this).find (".ui-btn-text").text ("Volume ON");

  }

});


</script>

tistory435_02.html




버튼의 상태를 select attribute에 보관해 두고 있죠? (디폴트는 true) 입니다. 그래서 이 값이 true 이면 버튼은 ON 이고 false 이면 버튼은 OFF 가 됩니다. 아이콘은 ui-icon CSS class 에서 처리되구요 텍스트는 ui-btn-text class를 통해서 처리 됩니다.


처음 페이지를 열면 아래와 같을 겁니다.




버튼을 클릭하면 글자가 OFF 로 바뀝니다.





Display a dynamically Delete button on a list item


이제 구현할 기능은 버튼을 동적으로 생성하는 겁니다. 화면에 리스트가 있고 그 리스트 중의 한 아이템을 오른쪽으로 drag 하면 delete 버튼이 생깁니다. 그리고 그 delete 버튼을 누르면 해당 아이템이 지워지는 겁니다.

아이폰의 메일에 이와 비슷한 기능이 있습니다.


Delete button added dynamically


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  

  <style type=text/css>

    .remove {

      position : absolute;

      right : 10px;

      top : 5px;

      font-size : 13px;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <ul data-role=listview data-inset=true>

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("swiperight", function (event)

{

  if ($(this).find (".remove").length) return;

  $(this).append ("<input type=button value=Delete class=remove />");

  $("input.remove").unbind ().bind ("click", function (event)

  {  

    $(this).closest ("li").remove ();

    $("ul").find ("li:first").addClass ("ui-corner-top");

    $("ul").find ("li:last").addClass ("ui-corner-bottom");

  });

});


</script>

tistory435_03.html




Delete button은 해당 리스트 아이템에 버튼이 없을 경우에만 생성됩니다. 그리고 이 버튼을 누르면 해당 아이템이 delete 됩니다.




여기서 Delete button이 생겨난 이후에 꼭 버튼만 클릭하는게 아니라 해당 아이템을 클릭하면 그 아이템이 지워지게 하면 재밌을 까요? 이를 위해서는 다음 예제를 참고하세요.


Hide the Delete button by clicking outside the button


버튼 밖을 클릭해서 해당 아이템이 지워지도록 하려면 아래 코드를 자바스크립트 안에 추가하세요.


Remove the Delete button when clicking outside the button


$("li").bind ("vclick", function (event)

{

    $(this).find ("input.remove").remove ();

});



이 코드는 약간의 문제가 있습니다.


해결 방법은 리스트 아이템에 time-out 을 넣는 겁니다. 이렇게 되면 버튼을 클릭해도 제대로 작동할 겁니다.


Inclusion of a delay in the removal of the button


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  

  <style type=text/css>

    .remove {

      position : absolute;

      right : 10px;

      top : 5px;

      font-size : 13px;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <ul data-role=listview data-inset=true>

      <li> Element 1 </li>

      <li> Element 2 </li>

      <li> Element 3 </li>

      <li> Element 4 </li>

      <li> Element 5 </li>

    </ul>

  </div>

</div>


</body>

</html>


<script>


$("li").bind ("swiperight", function (event)

{

  if ($(this).find (".remove").length) return;

  $(this).append ("<input type=button value=Delete class=remove />");

  $("input.remove").unbind ().bind ("click", function (event)

  {  

    $(this).closest ("li").remove ();

    $("ul").find ("li:first").addClass ("ui-corner-top");

    $("ul").find ("li:last").addClass ("ui-corner-bottom");

  });

});


$("li").bind ("vclick", function (event)

{

  var $this = $(this);

  setTimeout (function ()

  {

    $this.find ("input.remove").remove ();

  }, 500);

});


</script>



tistory435_04.html


이 소스에서는 버튼을 클릭하는 시간을 0.5초 줬습니다. 이 시간 동안에는 리스트 아이템은 remove 되지 않을 겁니다. 그 다음에 버튼이 delete 되겠죠.







반응형

버튼 Customize 하기

2012. 10. 31. 04:30 | Posted by 솔웅


반응형
Customize buttons



General appearance of the button



이전 글에서 만들었던 소스를 firefox 의 firebug 를 통해서 jQuery 에 의해 생성된 HTML 소스를 보겠습니다.



<a> link 는 이제 ui-btn CSS class 가 됐죠? 그리고 안에 ui-btn-inner CSS class가 있는 <span> element 도 포함하고 있습니다. 그 안에는 ui-btn-text class 를 가지고 있는 <span> element가 있습니다.


이제 버튼의 style을 원하는 대로 바꿀 수 있겠죠? ui-btn-text CSS class 를 따로 override 해서 정리하면 버튼 스타일을 customize 할 수 있습니다.


Changing the style of the button


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

  

  <style type=text/css>

    .ui-btn-inner {

      padding : 25px;

      background-color : black;

    }

    .ui-btn-text {

      font-size : 25px;

      color : white;

    }

  </style>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <a id=btn data-role=button href=#> Click here </a>

  </div>

</div>


</body>

</html>


<script>


$("#btn").bind ("click", function (event)

{

  alert ("click");

});


</script>



tistory434_01.html


이렇게 하면 색다른 모양의 버튼이 보일 겁니다.





Aspect of the clicked button


버튼이 눌렸을 때 jQuery Mobile은 ui-btn-down-c CSS class를 assign 합니다. 클래스 이름 끝의 "c"는 default theme button 을 말하는 겁니다. data-theme attribute 에 의해 modify 될 수 있습니다.  이 클래스도 따로 CSS 클래스로 implement 할 수 있습니다.


Adding the CSS class ui-btn-down-c in the styles of buttons


<style type=text/css>

 .ui-btn-inner {

    padding : 25px;

    background-color : black;

  }

  .ui-btn-text {

    font-size : 25px;

    color : white;

  }

  .ui-btn-down-c {

    font-style : italic;

  }

</style>

tistory434_02.html


위 코드를 적용하면 버튼이 클릭될 때 글자가 이탤릭체로 될 겁니다.


특정 CSS property를 사용할 때 주의하실 부분이 있습니다. 예를 들어 ui-btn-down-c class 정의 부분에 color property를 다시 사용하신다면 child element (the <span> with the ui-btn-text CSS class) 안에 재 정의 된 것으로 적용 되지 않을 겁니다. 제대로 처리 되게 하려면 아래와 같이 하셔야 합니다.


Changing the text color when the button is clicked


<style type=text/css>

  .ui-btn-inner {

    padding : 25px;

    background-color : black;

  }

  .ui-btn-text {

    font-size : 25px;

    color : white;

  }

  .ui-btn-down-c {

    font-style : italic;

  }

  .ui-btn-down-c .ui-btn-text {

    color : red;

  }

</style>


tistory434_03.html


이렇게 하면 버튼을 누를 때 글자가 이탤릭 체로 되면서 글자 색도 빨간색으로 바뀌도록 할 수 있습니다.






반응형


반응형
Manage events on buttons


리스트와 마찬가지로 버튼에서 발생할 수 있는 main event 는 click event 입니다. 이 이벤트는 jQuery 의 bind () method 의해 클릭 됐을 때 어떤 동작을 하도록 처리 됩니다.


Process the click on the button


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

    <a id=btn data-role=button href=#> Click here </a>

  </div>

</div>


</body>

</html>


<script>


$("#btn").bind ("click", function (event)

{

  alert ("click");

});


</script>



tistory433_01.html



jQuery Mobile은 여기서 vclick event  가 아니라 click event 를 사용할 것을 권장합니다.


반응형

Ajax 로 버튼 insert 하기

2012. 10. 30. 03:41 | Posted by 솔웅


반응형
Insert buttons by Ajax

이제 Ajax를 통해서 HTML element를 버튼으로 만들어서 화면에 그 버튼을 표시하려고 합니다. 첫번째 버튼은 링크 처럼 <a> element 이고 두번째 버튼은 type="submit" attribute 를 가지고 있는 <input> button 이 될 것입니다.


Insert buttons in a window via Ajax


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


$.ajax (

{

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home div:jqmData(role=content)").append (response);

    $("#btn").button ();

    $("input[type=submit]").button ();

  }

});    


</script>



서버에 있는 action.php file 이 이 두개의 버튼을 만들 HTML 코드를 return 할 겁니다.


action.php file


<?
$html = "";
$html .= "<a id=btn href=#>Menu 1</a>";
$html .= "<input type=submit value=Submit />";
  
echo utf8_encode ($html);

?>


action3.php


tistory431_01.html



서버로부터 소스를 받을 시간동안 약간 기다리면 두개의 버튼이 화면에 뜨시는 것을 보실 겁니다.

자바스크립트 부분을 잘 보세요. button () method를 사용했습니다. 이 메소드는 서버로부터 받은 두개의 HTML element들을 jQuery Mobile 에 의해 standard button들로 화면에 뿌려주도록 합니다. 만약 소스가 잘 못됐던가 해서 이 과정이 실패하면 화면에는 링크와 일반적인 HTML 버튼이 뿌려질겁니다.




다른 jQuery Mobile component들과 같이 component를 생성하는 standard method 는 (button () method 같은) 그 버튼을 포함한 element에서trigger ("create") method를 call 함으로서 구현할 수도 있습니다. 아래에 예제를 보시겠습니다.


Use the create event to create the button


<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


$.ajax (

  url : "action.php", 

  complete : function (xhr, result)

  {

    if (result != "success") return;

    var response = xhr.responseText;

    $("#home div:jqmData(role=content)").append (response);

    $("#home").trigger ("create");

  }

});


</script>



하나의 create event로 두개의 버튼을 생성할 수 있습니다. 여기서 첫번째 버튼에다가 이것을 button component로 바꿀 거라는 것을 알리기 위해 data-role="button" attribute를 추가 해야 합니다 두번째 버튼에는 <input> element 이기 때문에 필요없습니다.


action.php file


<?
$html = "";
$html .= "<a id=btn data-role=button href=#>Menu 1</a>";
$html .= "<input type=submit value=Submit />";
  
echo utf8_encode ($html);
?>

action4.php


tistory432_02.html




반응형


반응형

Turning a HTML element into a jQuery Mobile button


For an element to be transformed into a button, use the button () method on the HTML element.

Using the button () method

<!DOCTYPE html>

<html> 

<head> 

  <meta name=viewport content="user-scalable=no,width=device-width" />

  <link rel=stylesheet href=jquery.mobile/jquery.mobile.css />

  <script src=jquery.js></script>

  <script src=jquery.mobile/jquery.mobile.js></script>

</head> 


<body> 


<div data-role=page id=home>

  <div data-role=header>

    <h1>Home</h1>

  </div>


  <div data-role=content>

    <p> Window content </p>  

  </div>

</div>


</body>

</html>


<script>


var html = "";

html += "<a id=btn href=#>";

html +=     "Click the button";

html += "</a>";

$("#home div:jqmData(role=content)").append (html);


$("#home").bind ("pagecreate", function ()

  $("#btn").button ();

});


</script>


Note that the window is expected to be created to transform the link into button (pagecreate event). However, in the case of buttons, it is not necessary, unlike the lists that we have previously studied. But for the sake of thoroughness, we try to write similar code in both cases ...





tistory430_02.html



반응형