【问题标题】:show and hide multible div's depend on 3 select boxes values显示和隐藏多个 div 取决于 3 个选择框值
【发布时间】:2012-04-04 00:57:47
【问题描述】:

我有 3 个包含许多选项的选择列表 我不知道任何JS代码 这是我的 HTML

<fieldset id="basic_data">
                <legend>Basic Data :</legend>
                    <h3 class="floatright">Type</h3>
                    <select class="" id="choosebuilding" name="choosebuilding">
                        <option value="flat">flat</option>
                        <option value="villa">villa</option>
                        <option value="3">commercial</option>
                        <option value="4">land</option>
                    </select>
                        <div class="clear"></div>
                    <h3 class="floatright">Payment</h3>
                    <select class="" id="choosecity" name="choosetype">
                        <option value="1">cash</option>
                        <option value="2">installement</option>
                        <option value="3">rent</option>
                        <option value="4">furnished</option>
                    </select>
                        <div class="clear"></div>
                    <h3 class="floatright">Choose City</h3>
                    <select class="" id="choosecity" name="choosecity">
                        <option value="1">Alrehab</option>
                        <option value="2">Settlement</option>
                        <option value="3">Madinty</option>
                    </select>
                </fieldset><!-- end field set Basic Data -->

而且我有许多显示依赖关系的字段集 像这样

-- 地址数据 IF Alrehab + Madinty type flat --

-- 地址数据 IF Alrehab + Madinty 型别墅--

-- 地址数据全部商用--

-- 地址数据结算类型flat OR 和别墅--

-- 现金 Alrehab + Madinty --

-- 货币现金结算--

-- Credite Alrehab + Madinty --

-- 信用结算--

-- 全部出租--

-- 全部装修--

我相信我有很多案例

我将所有必要的字段都放在了我的 html 中,并像这样评论了它。

我想显示已使用的字段部分并隐藏其他字段

我的隐藏代码示例

<fieldset id="furnished">
                    <legend>Furnished - All :</legend>
                        <h3 class="floatright">coast</h3>
                        <input name="rental_sum" class="input100" />

                        <h3 class="floatright">dialy</h3>
                        <input name="daily_rent" class="input100" />

                        <h3 class="floatright">insurance</h3>
                        <input name="insurance" class="input100" />

                        <h3 class="floatright">staff</h3>
                        <input name="annual_increas" class="input100" />

                        <h3 class="floatright">less</h3>
                        <input name="less_rent_time" class="input100" />

                        <h3 class="floatright">when ready</h3>
                        <input name="" class="input100" />

                    </fieldset><!-- end field set 11 -->

【问题讨论】:

  • 你有什么问题? “我想显示已使用的字段部分并隐藏其他部分”没有意义。
  • 这没有多大意义。如果您想要回复,我建议您重写问题。另外,为什么不尝试学习一些 javascript 并先尝试自己解决问题。如果你使用jquery,这很容易

标签: javascript html forms dependencies


【解决方案1】:

看起来是 jQuery show()、hide() 和一些逻辑的好地方。

function updateShown(){
//First, hide everything that may have been previously shown.
  $("#furnished").hide();

//Next, start showing things based on user's selections
  //if ("Alrehab" or "Madinty") and ("flat" or "villa"), show addressData
  if ($("#choosecity").val() == 1 || $("#choosecity").val() == 3)
          && ($("#choosebuilding").val() == "flat" || $("#choosebuilding").val() == "villa") ){
      $("#addressData").show();
  }
}

updateShown() 添加到选择的.change 事件中,您应该已经设置好了。

【讨论】:

  • 我试过了,但我好像弄乱了一些东西..我不知道我会用这段代码做什么?
猜你喜欢
  • 2014-11-18
  • 1970-01-01
  • 2018-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-27
  • 1970-01-01
  • 2015-10-10
相关资源
最近更新 更多