0

複数の入力フィールドを持つポップアップがいくつかあります。すべてのポップアップの FIRSTinput 要素を強調表示したいのですが、ID を使用したくありません。

私のコード:

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();
            }
        });
    });

1 つのポップアップの html を次に示します。

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

私のコードは、HTML ファイルの最初の入力フィールドのみを強調表示し、すべてのポップアップ (静的 html にある) の最初の入力フィールドは強調表示しません。

4

2 に答える 2

1

@Trufa の助けを借りて、次の方法で修正しました。

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画面上にあるときにクラスを取得するので、それを使用して最初の入力フィールドを強調表示するだけです:)

于 2012-12-14T23:44:25.833 に答える
0

を使用して、 :内のjQuery要素[0]の「配列」の最初の要素を選択してみてください。inputform

popupafteropen:function(){
    console.log("OPENED");
    $('div[data-role=popup] input[type!=hidden]')[0].focus();
}
于 2012-12-14T22:37:48.080 に答える