jQuery Mobile Показать / Скрыть форму ввода на основе поля выбора - PullRequest
1 голос
/ 08 марта 2012

У меня есть следующие поля формы на моей странице jQuery Mobile. Я хочу сначала скрыть элемент, а затем иметь его .show (), если пользователь выбирает параметр со значением = "Другое"

Вот мой HTML:

<div data-role="fieldcontain" class="no-field-separator">
        <select name="plan_height" id="plan_height" data-native-menu="false">
          <option>Plan Height</option>
          <option value="Standard 6foot 2inch">Standard 6'2"</option>
          <option value="Other">Specify in Notes</option>
        </select>
      </div>
      <div id="specify_plan_height_box" style="display:none;">
        <div data-role="fieldcontain" class="ui-hide-label no-field-separator">
          <label for="specify_plan_height">Specify Plan Height</label>
          <input type="text" id="specify_plan_height" name="specify_plan_height" placeholder="Specify Plan Height" maxlength="50" />
        </div>
      </div>

и вот мой JS ВНУТРИ страницы:

 // $( '#machine-guarding-page' ).live( 'pageinit',function(event) {
$( document ).bind( "pageinit", function( event, data ) {
    $('#plan_height').change(function() {
        var planHeightVal = $("#plan_height option:selected").val();
        var sphb          = $("#specify_plan_height_box");

        sphb.hide();
        if (planHeightVal == "Other") {
            sphb.show();
        }
    });
});
    });

Здесь, в этом рабочем примере, работает нормально. Нужно ли иметь что-то кроме $(".page").live('pageinit', function() { вверху моего кода JS, чтобы он работал после загрузки страницы? Это прекрасно работает в приведенном выше примере ссылки, но не на моем сайте jQuery Mobile.

1 Ответ

2 голосов
/ 08 марта 2012

Работает ли это для вас:

...