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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형
Manage events on input fields


input field는 standard event들을 receive 합니다. 그리고 jQuery 의 bind () method에 의해서 observe 될 수 있습니다. jQuery Mobile 터치 스크린이든 기존 컴퓨터이든 같은 이벤트 이름을 사용한다는 걸 기억해 두세요.


Events on the input fields


Name

Signification

click

vclick

A click was made in the field.

focus

The field has just won the focus.

blur

The field has lost focus.

change

The field content has changed (detected when the field loses focus).

keyup

A keyboard key was pressed.

keydown

A keyboard key was released.

mousedown

vmousedown

The left mouse button was pressed (or the finger touched the field).

mouseup

vmouseup

The left mouse button was released (or the finger was removed from the screen).



Taking into account of a click in an input field


<!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 += "Name : <input type=text value='Sarrion' />";

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


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

{

  alert ("click");

});


</script>


tistory458_01.html




Taking into account of a click in a search field


<!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 += "Search : <input type=search value='Your name' id=search />";

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


$("#search").live ("textinputcreate", function (event)

{

  $("#search").bind ("vclick", function (event)

  {

    alert ("click");

  });

});


</script>

tistory458_02.html



이 예제에서는 search field 가 생성될 때 까지 기다려야 합니다. 안 그러면
<input> element 가 사용하는 bind ("vclick" ...)이 실제 bind ()가 실행 될 때 존재하지 않은 상태가 됩니다. search field 의 HTML 이 자바스크립트에 의해서가 아니라  HTML 로 곧바로 insert 될 때도 같은 문제점이 발생합니다. 아래 예제를 보겠습니다.


Search field inserted directly into the HTML


<!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>  

    Search : <input type=search value="Your name" id=search />

  </div>

</div>


</body>

</html>


<script>


$("#search").live ("textinputcreate", function (event)

{

  $("#search").bind ("vclick", function (event)

  {

    alert ("click");

  });

});


</script>



tistory458_03.html


위에서 설명드렸듯이 textinputcreate event를 다루면서 click event (or vclick)를 연결시키는 것이 핵심입니다. 안 그러면 click 은 연결되지 않을 겁니다.



반응형