惹不起_溜了 2019-03-04 10:13 采纳率: 66.7%
浏览 512
已采纳

MVC项目,根据判断条件决定文本框还是下拉框

要求根据视图中变更项目(CICD)决定变更值(CHV)是text还是dropdownlist

<tr>
            <th style="width:20%"><font class="redstar">*</font>变更项目</th>
            <td>
                @Html.DropDownListFor(model => model.CICD, new SelectList(Dics.GetItems(Dics.DicTypes.itmJczBgxm, true), "CD", "NM", "20"),new { onchange = "MinDate()" })
                @Html.ValidationMessageFor(model => model.CICD)
            </td>
        </tr>
        <tr>
        <tr>
            <th>变更值</th>
            <td>
                @Html.TextBoxFor(model => model.CHV, new { htmlAttributes = new { } })
                @Html.ValidationMessageFor(model => model.CHV)
            </td>
        </tr>

我的思路是:绑定onblur()方法,使用ajax提交到后台,从后台进行判断。

视图中js语句:

function ChoseInputStyle() {
            var a = $('#CICD').val();
            $.ajax({
                type: "post",
                //dataType:"json",
                url: '/StchAtt/InputStyle ',
                data: {cicd: a },
                success: function (data) {
                    if (data == "jczlb") {
                        $('#CHV').
                                                //这里不会写
                    }


            });
        }

控制器中方法:

public string InputStyle(string cicd)
        {
            string input = "";
            if (cicd != null)
            {
                if(cicd=="01" || cicd == "02" || cicd == "05" || cicd == "06" || cicd == "07")
                {
                    input = "text";
                    return input;
                }
                else if (cicd == "08")
                {
                    //jczlb--"监测站类别"首字母
                    input = "jczlb";
                    return input;
                }
            }
            return input;
        }

希望各位大神们bang'bang'mang

  • 写回答

2条回答 默认 最新

  • Stone丶y 2019-03-04 10:52
    关注
            if(data.value=='你进行判断的字段'){
                $("#result").parent().empty();//获取对象父级元素清空
                var innerHtml = "你要写的下拉框";
                $('#你所在的div').append(innerHtml)
    
            }else{
                $("#result").parent().empty();//获取对象父级元素清空
                var innerHtml ="<input  type=\"text\" id=\"result\"    style=\"width:180px;\"    maxlength=\"18\"  />";
                $('#resultdiv').append(innerHtml)
            };
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?