首页 > 作文

js三级联动下拉框怎么实现(前端三级联动实现代码)

更新时间:2023-04-05 06:06:35 阅读: 评论:0

数据库:

u master

go

if exists(lect * from sysdatabas where name=’stu1′)

drop databa stu1

go

create databa stu1

on

(

name=’stu1′,

filename=’d:\sql\stu1.mdf’,

size=4,

filegrowth=10%

)

log on

(

name=’stu1_log’,

filename=’d:\sql\stu1_log.ldf’,

size=4,

filegrowth=10%

)

go

u stu1

go

if exists(lect * from sysobjects w仿写安塞腰鼓here name=’class’)

drop databa class

go

create table class

(

id int identity primary key,

name varchar(20),

direction varchar(20)

)

inrt into class

lect ‘2012271’,’.net’ union

lect ‘2012272’,’j2ee’ union

lect ‘2012273’,’.net’ union

lect ‘2012274’,’j2ee’ union

lect ‘2012275’,’j2ee’ union

lect ‘2012276’,’.net’ union

lect ‘2012277’ ,’.net’

go

lect * from class

if exists(lect * from sysobjects where name=’student’)

drop table student

go

create table student

(

id int identity primary key,

name varchar(20),

x bit check(x in(1,0)),

age int,

address varchar(30),

hobby varchar(30),

c_id int

)

go

inrt into student

lect ‘张三’,0,20,’内蒙赤峰’,’睡觉,聊天’,1 union

lect ‘李颂’,1,19,’湖北襄樊’,’逛街’,2 union

lect ‘吕两口’,0,18,’东北’,’轮滑’,3 union

lect ‘小斌’,1,20,’湖北十堰’,’做菜’,3 union

lect ‘哦哦’,0,19,’湖北枣阳’,’吃’,4 union

lect ‘康康’,1,22,’河南南阳’,’看美女’,5 union

lect ‘帅帅’,1,18,’湖北武汉’,’睡’,5 union

lect ‘忽忽’,1,22,’陕西西安’,’游戏’,6 union

lect ‘cc’,1,22,’湖北十堰’,’拼酒’,6 union

lect ‘小剑’,0,18,’深圳’,’看mm’,7 union

lect ‘勇勇’,1,19,’湖北十堰’,’吃了嘻嘻睡’,7

go

lect * from class

lect * from student,class where student.c_id=class.id

lect * from class

html 文件:

<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en” “/d/file/titlepic/pp<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>

<title></title>

<script src=”jquery1.8.3/jquery-1.8.3.min.js” type=”text/javascript”></script>

<script src=”jquery1.8.3/json2.js” type=”text/javascript”></script>

<script type=”text/javascript”>

$(function () {

$.ajax({

type: “post”,

url: “a.ashx”,

success: function (msg) {

var ok = json.par(msg);

$.each(ok.datatable, function(i, j) {

var op = new option(); //创建option对象

op.value = j.id; //option里面的value

op.text = j.name; //显示的值

//alert(op.text);

//把内容加载到lect里面

document.getelementbyid(“st1”).add(op);

});

}

});

$(“#st1”).change(function () {

var str = $(“#st1”).val();

$.ajax({

type: “post”,

url: “b.ashx”,

data: { id: str },

success: function(msg) {

var kk = json.par(msg);

$(“#st2”).empty();

var s = $(“#tbody”).html(“”);

$.each(kk.datatable, function(o, n) {

var op1 = new option(); //创建option对象

op1.value = n.id; //option里面的value

op1.text = n.name; //显示的值

document.getelementbyid(“st2”).add(op1);

$(“#stu”).attr(“style”, “display:black”);

var x = (n.x == ‘true’) ? “男” : “女”;

$(“#tbody”).append(隋朝之前是什么朝代“<tr><td>” + n.name + “</td><td>” + x + “</td><td>” + n.age + “</td><td>” + n.address + “</td><td>” + n.hobby + “</td><td>” + n.classname + “</td></tr>”);

});

}

});

});

$(“#st2”).change(function () {

var sid = $(“#st2”).val();

var s = $(“#tbody”).html(“”);

$.ajax({

type: “post”,

url: “c.ashx”,

data: { id: sid },

success: function(msg) {

var ok = json.par(msg);

$.each(ok.datatable, function(l, p) {

$(“#stu”).attr(“style”, “display:black”);

var x1 = (p.x == ‘true’) ? “男” : “女”;

$(“#tbody”).append(“<tr><td>” + p.name + “</td><td>” + x1 + “</td><td>” + p.age + “</td><td>” + p.address + “</td><td>” + p.hobby + “</td><td>” + p.classname + “</td></tr>”);

});

}

});

});

})

</script>

</head>

<body>

<lect id三月再见四月你好图片=”st1″></lect>班级

<lect id=”st2″></lect>学生姓名

<br />

<div id=”stu” style=” display:none”>

<table border=”1″ id=”tab” cellspacing=”0″ cellpadding=”0″ width=”500″>

<thead>

<tr>

<th>学生姓名</th>

<th>学生性别</th>

<th>学生年龄</th>

<th>学生住址</th>

<th>学生爱好</th>

<th>所在班级</th>

</tr>

</thead>

<tbody id=”tbody”></tbody>

</table>

</div>

</body>

</html>

a.ashx 文件:

public class a : ihttphandler

{

public void processrequest(httpcontex求函数的定义域t context)

{

context.respon.contenttype = “text/plain”;

datatable dt = gettable();

string str = jsonhelper.datatabletojsonex(dt);

context.respon.write(str);

}

datatable gettable()

{

return sqlhelper.gettable(“lect id,name from class”);

}

public bool isreusable

{

get

{

return fal;

}

}

}

b.ashx 文件

public class b : ihttphandler

{

public void processrequest(httpcontext context)

{

context.respon.contenttype = “text/plain”;

int id = int.par(context.request[“id”].tostring());

datatable dt = gettable(id);

string ss = jsonhelper.datatabletojsonex(dt);

context.respon.write(ss);

}

datatable gettable(int id)

{

stringbuilder sb = new stringbuilder();

sb.append(” lect s.id as id,s.name as name,s.x as x, “);

sb.append(” s.age as age,s.address as address, “);

sb.append(” s.hobby as hobby,c.name as classname “);

sb.append(” from student as s,class as c “);

string sql = string.empty;

sql = sb.tostring();

sql += string.format(“where s.c_id=c.id and c.id={0}”,id);

// string sql = string.format(“lect * from student where c_id={0}”,id);

return sqlhelper.gettable(sql);

}

public bool isreusable

{

get

{

return fal;

}

}

}

c.ashx 文件

public class c : ihttphandler

{

public void processrequest(httpcontext context)

{

context.respon.contenttype = “text/plain”;

int id = int.par(context.request[“id”].tostring());

datatable dt = gettable(id);

string ss = jsonhelper.datatabletojsonex(dt);

context.respon.write(ss);

}

datatable gettable(int id)

{

stringbuilder sb = new stringbuilder();

sb.append(” lect s.name as name,s.x as x,s.age as age, “);

sb.append(” s.address as address,s.hobby as hobby, “);

sb.append(” c.name as classname from student as s,class as c “);

string sql = string.empty;

sql = sb.tostring();

sql += string.format(“where s.c_id=c.id and s.id={0}”,id);

// string sql = string.format(“lect s.name as name,s.x as x,s.age as age,s.address as address,s.hobby as hobby,c.name as classname from student as s,class as c where s.c_id=c.id and s.id={0}”, id);

return sqlhelper.gettable(sql);

}

public bool isreusable

{

get

{

return fal;

}

}

}

jsonhelper.cs 辅助文件

using system;

using system.collections.generic;

using system.linq;

using system.web;

using system.data;

using system.text;

using system.web.script.rialization;

/// <summary>

///jsonhelper 的摘要说明

/// </summary>

public class jsonhelper

{

private static list<dictionary<string, object>> datatabletolist(datatable table)

{

list<dictionary<string, object>> list = new list<dictionary<string, object>>();

foreach (datarow row in table.rows)

{

dictionary<string, object> dic = new dictionary<string, object>();

foreach (datacolumn column in table.columns)

{

dic.add(column.columnname,row[column.columnname]);

}

list.add(dic);

}

return list;

}

public static string objecttojson(object obj)

{

javascriptrializer jss = new javascriptrializer();

return jss.riali百年校庆诗歌ze(obj);

}

public static string datatabletojson(datatable table)

{

return objecttojson(datatabletolist(table));

}

/// <summary>

/// 通过拼字符串将datatable转为json

/// </summary>

/// <param name=”table”></param>

/// <returns></returns>

public static string datatabletojsonex(datatable table)

{

string jsonname = “datatable”;

stringbuilder json = new stringbuilder(“{\”” + jsonname + “\”:[“);

if (table.rows.count > 0)

{

foreach (datarow row in table.rows)

{

json.append(“{“);

foreach (datacolumn column in table.columns)

{

json.append(“\”” + column.columnname + “\”:\”” + row[column.columnname].tostring() + “\”,”);

}

json.remove(json.length – 1, 1);

json.append(“},”);

}

json.remove(json.length – 1, 1);

}

json.append(“]}”);

return json.tostring();

}

}

本文发布于:2023-04-05 06:06:18,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/1734f0f27a98670bf53cf8022a75b011.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:js三级联动下拉框怎么实现(前端三级联动实现代码).doc

本文 PDF 下载地址:js三级联动下拉框怎么实现(前端三级联动实现代码).pdf

标签:湖北   学生   文件   安塞
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图