javascript - jQuery Mobile 显示/隐藏基于选择字段的表单输入

标签 javascript jquery jquery-mobile toggle forms

我的 jQuery Mobile 页面上有以下表单字段。我想最初隐藏该元素,然后如果用户选择 value="Other"

的选项,则将其 .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();
        }
    });
});
    });

在这个 working example 中工作正常.除了 $(".page").live('pageinit', function() { 在我的 JS 代码的顶部使其在页面加载后工作?它在上面的示例链接中工作正常,但在我的 jQuery Mobile 网站上却不行。

最佳答案

这对你有用吗:

关于javascript - jQuery Mobile 显示/隐藏基于选择字段的表单输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9619552/

相关文章:

javascript - 更改占位符文本

javascript - JQuery UI 可拖动来调整 div 大小

javascript - 如何让 JavaScript 找到焦点输入的值,如果是默认值则清除,如果是新数据则保留?

jquery - 选中和取消选中具有不同名称的单选按钮

javascript - 使用 native 功能增强 Web 应用程序 - 将 PhoneGap 的 InAppBrowser 与 Rails Web 应用程序应用程序 javascript 桥接

javascript - 通过 Jquery 改变 Div 的高度和宽度

javascript - 为什么 "message.channel.find"不是函数?

javascript - JQuery 自动完成缓存与 ajax 不填充

jquery - 您可以在不更改 html 的情况下覆盖白色和黑色的 Jquery 移动股票图标吗?

c# - 使用/jquery mobile、c# 和 asp.net 延迟加载 SELECT 元素选项