如何在编辑视图中使用dropdownlist使用show和hide div? [英] how can we use show and hide div using dropdownlist in edit view?

查看:60
本文介绍了如何在编辑视图中使用dropdownlist使用show和hide div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
    function showHideDivs(elem) {
        var divsObj = document.getElementsByClassName('showHideDivs');
        for (i = 0; i < divsObj.length; i++) {

            divsObj[i].style.display = (divsObj[i].id == 'd' + elem.value) ? 'block' : 'none';

        }

    }

</script>
  <div class="editor-label">
            @Html.LabelFor(model =&gt; model.custMain.CTypeID)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model =&gt; model.custMain.CTypeID, (IEnumerable<SelectListItem>)ViewBag.ClientType, "Select Client Type", new { @class = "showHIdeDivs", @onchange = "showHideDivs(this)", id = "cid" })
            @Html.ValidationMessageFor(model =&gt; model.custMain.CTypeID)
        </div>
 <div class="showHideDivs" id="d1"></div>


推荐答案

任何方式都可以.您已经在此处编写了代码,行得通吗?您想做什么?下拉列表的选择如何定义您希望div显示的方式?
Any way you like. You have written code here, does it work ? What do you WANT it to do ? How does the selection of a drop down list define the way you want the divs to show ?


这篇关于如何在编辑视图中使用dropdownlist使用show和hide div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆