2012-12-14 3 views
0

여러 개의 입력 필드가있는 팝업이 여러 개 있습니다. 내 모든 팝업의 FIRSTinput 요소를 강조하고자, 나는 ID를 사용하지 않으 :jquery를 사용하여 팝업의 첫 번째 입력 요소 강조 표시

내 코드 :

<div data-role="popup" id="create_stationPopup" class="ui-content"> 
      <a href="#" data-rel="back" data-role="button" data-theme="c" data-icon="delete" data-iconpos="notext" 
       class="ui-btn-right">Close</a> 
      <form> 
      <input type="text" name="name" id="station_input_title" value="" data-mini="true" placeholder="Titel der Station" /> 
      <input type="text" name="name" id="station_input_number" value="" data-mini="true" placeholder="Nummer der Station"/> 
      <textarea name="textarea" id="station_input_text" placeholder="Beschreibe diese Station"></textarea> 
      </form> 
      <a href="#create_stationQuestionPopup" data-rel="popup" data-role="button" data-theme="c" id="createWave_questionBtn" >Frage 
       hinzufügen</a> 
      <a id="createWave_stationSaveBtn" data-role="button" data-theme="c">Station 
       speichern</a> 
     </div> 

: 여기

function initPopups(){ 
    $('*[id*=Popup]').each(function() { 
     $(this).on({ 
        // disables the auto close on outer clicks 
      popupbeforeposition: function() { 
       // removes all handlers from the 'background'(-layer.class) of the popup 
       $('.ui-popup-screen').off(); 
      }, 
        // SHOULD highlight the first textfield after popup opened 
      popupafteropen:function(){ 
       console.log("OPENED"); 
        $('form:first *:input[type!=hidden]:first').focus(); 
      } 
     }); 
    }); 

한 팝업의 HTML입니다 내 코드는 HTML 파일의 첫 번째 입력 필드 만 강조 표시합니다 (정적 HTML에있는 모든 팝업의 첫 번째 입력 필드가 아님)

+0

정확히 어떤 플러그인을 사용하고 있습니까? 질문 : 분명하지 않습니다. ( – sakhunzai

+0

jQuery 모바일을 사용하고 있습니까? – David

+0

jquery mobile 예. – MJB

답변

1

@Trufa의 도움으로 나는 그에게 다음과 같은 방법으로 고정 화면, 그래서 간단하게 그것을 사용하여 첫 번째 입력란을 강조 표시 :)

0

[0]을 사용하여 첫 번째 요소 i를 선택하십시오. 이 켜져있을 때

function initPopups(){ 
    $('*[id*=Popup]').each(function() { 
     $(this).on({ 
      popupbeforeposition: function() { 
       // removes all handlers from the 'background'(-layer.class) of the popup 
       $('.ui-popup-screen').off(); 

      }, 
      popupafteropen:function(){ 
        $('.ui-popup-active *:input[type!=hidden]:first').focus(); 
       } 
     }); 
    }); 
} 

모든 팝업 클래스 .ui-popup-active를 가져옵니다 jQuery를의 input 소자들 form에서 n은 '배열'

popupafteropen:function(){ 
    console.log("OPENED"); 
    $('div[data-role=popup] input[type!=hidden]')[0].focus(); 
} 
+0

슬프게도 작동하지 않습니다. – MJB

관련 문제