一个二级联动
<div class="layui-form-item"> <label class="layui-form-label">所属级别:</label> <div class="layui-input-inline"> <input type="hidden" id="nitemtype" name="nitemtype" value="" /> @*@html.dropdownlistfor(m => m.meid, menuhelper.getme(), new { @jqverify = "required", @jqerror = "请选择级别" })**@
//循环插入 <select name="itemselect" id="itemselect" lay-filter="itemselect" @(type != 0 ? "disabled" : "")> <option value="0">选择级别</option> @{ //foreach (doingstudy.entity.news_menu imodel in new doingstudy.repository.news_menu().iqueryable("menuid", 0))
foreach (doingstudy.entity.news_menu imodel in new doingstudy.repository.news_menu().iqueryable("pid", 0)) { string skey = string.empty; if (nmenuid == imodel.menuid) { skey = " selected=\"selected\" "; } <option @skey value="@imodel.menuid">@imodel.menuname</option> } } </select> </div> <div class="layui-input-inline"> <select name="professionid" id="professionid"> @{ <option value="0">全部 </option> if (nmenuid != 0) { list<doingstudy.entity.news_menu> nmodel = new doingstudy.repository.news_menu().findlist("pid", nmenuid); for (var i = 0; i < nmodel.count; i++) { string skey2 = string.empty; if (existid == nmodel[i].menuid) { skey2 = " selected=\"selected\" "; } <option @skey2 value="@nmodel[i].menuid">@nmodel[i].menuname</option> } } } </select> </div>
<script> layui.use('myform'); layui.use("form", function () { var form = layui.form(); form.on('select(itemselect)', function (data) { fillcity(data.value); document.getelementbyid('nitemtype').value = $("#itemselect").val(); }); //资讯类型 form.on('radio(newstype)', function (data) { if (data.value == 3) { $("#divvideo").show(); } else { if (data.value == 0) { $("#divphoto").hide(); } else { $("#divphoto").show(); } $("#divvideo").hide(); } }); }); function fillcity(provinceid) { $.ajax({ url: "/newsmanage/news/getmodulechildlist?pid=" + provinceid, type: "get", datatype: "json", success: function (cities) { $("#professionid").html(""); $.each(cities, function (i, city) { $("#professionid").append(("<option value='" + city.value + "'>" + city.text + "</option>")); }); layui.use("form", function () { var form = layui.form(); form.render(); }); } }); } </script>
[httpget] public string getmodulechildlist(int pid) { return system.web.mvc.menuhelper.getmodule(pid).tojson(); }//get请求
[httpget]
public actionresult jsonlist()
{
int itemselect = converthelper.saferequest("itemselect",0);//一级
int professionid = converthelper.saferequest("professionid", 0);//二级
int smenuid = 0;
if (professionid != 0)
{
smenuid = professionid;
}
else {
smenuid = itemselect;
}
string stitle = converthelper.safestring(request["txttitle"], "");
pagemodel page = pagemodelinstance.getinstance();
page.pagesize = pagesize;
page.pageindex = nowpage;
datatable dtlist = new doingstudy.repository.news_news().getlist(stitle, snewstype, smenuid, 0, isaudit, ishead, pagesize, nowpage, out rowscount);
[httppost]
public actionresult edit(doingstudy.entity.news_news model)
{
doingstudy.repository.news_news adminrep = new doingstudy.repository.news_news();
int itemselect = converthelper.saferequest("itemselect", 0);//一级
int professionid = converthelper.saferequest("professionid", 0);//二级
if (professionid != 0)
{
model.menuid = professionid;
}
效果图如图所示;
上一篇: 个人交易5万、转账20万以上将受监控
下一篇: oracle之trunc函数
推荐阅读
-
OpenGL学习之路3----画一个三角形
-
node.js - windows的服务器,一个文件夹最多能放多少个文件而不会影响php/nodejs/java等读取文件的速度?
-
Python实现按照指定要求逆序输出一个数字
-
请问一个快速排序法的有关问题
-
React如何操作?react从零开始的制作一个案例的全过程
-
thinkphp模板中添加了一个if标签后布局发生了改变,为什么会这样?
-
一个网站有多个后台,怎么让它们不相干
-
一个捕获函数输出的函数_PHP教程
-
photoshop cs5 官方中文正式原版下载 php的一个登录的类 [推荐]
-
给自己一个微笑 作文 随时给自己贴的图片加文字的php水印