下拉列表select中使用ajax的json数据交换格式动态改变div层里面的复选框checkbox值

前端之家收集整理的这篇文章主要介绍了下拉列表select中使用ajax的json数据交换格式动态改变div层里面的复选框checkbox值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
align=left][size=large]
function  doChange(f)
{
   if(f.value ==0)
   {
     document.getElementById("div").style.display="none";
      document.getElementById("good").style.display="block";
       document.getElementById("goods").style.display="none";
       document.getElementById("goods").value="";
   }else if(f.value ==1){
     document.getElementById("div").style.display="block";
      document.getElementById("good").style.display="none";
      document.getElementById("good").value="";
     document.getElementById("goods").style.display="block";
   }
   else{
    document.getElementById("div").style.display ="block";
        document.getElementById("good").style.display="none";
        document.getElementById("good").value="";
            document.getElementById("goods").style.display="none";
            document.getElementById("goods").value="";
   } 
   
}
---------------------------------------------------------
function getMissiveType(){
var typeScope=$('#typeScope').val();
$.ajax({
type:"POST",dataType:"json",url:"<%=path%>/pages/CommonSession/index.do",data:"doaction=searchByMissiveTypeScope&typeScope="+typeScope,success:function(data){
var len=data.length;
if(document.getElementById("good").style.display=="block"&&document.getElementById("goods").style.display 

=="none"){
$('#good').contents().remove();
for(i=0;i<len;i++){
$('#good').append("<input type='checkBox' name='missiveType' id='" + data[i].MISSIVE_TYPE_ID + " ' value='" + data

[i].MISSIVE_TYPE_ID + "'/>" + data[i].NAME + "<br />");
}
}
if(document.getElementById("good").style.display=="none"&&document.getElementById("goods").style.display 

=="block"){
$('#goods').contents().remove();
for(i=0;i<len;i++){
$('#goods').append("<input type='checkBox' name='missiveTypes' id='" + data[i].MISSIVE_TYPE_ID + " ' value='" + data

[i].MISSIVE_TYPE_ID + "'/>" + data[i].NAME + "<br />");
}
}
}
});
}
-------------------------------------------------------------
  <tr> 
            <td width="15%" height="30" bgcolor="E1EEFD" class="tablex">
            <div align="right">所属类型&nbsp;</div></td>
            <td width="55%" height="30" bgcolor="E1EEFD" class="tableleft">&nbsp; 
               <select name="typeScope" id="typeScope" style="width:51%" onchange="doChange(this);getMissiveType()"> 
                <option value="" selected="selected">--请选择--</option>
               		<option value="0" >公司</option>
               		<option value="1" >部门</option>
             </select>
            </td>
          </tr>
--------------------------------
            <tr id="div"> 
            <td height="30" bgcolor="ECF4FD" class="tablex">
                <div align="right">部门&nbsp;</div></td>
            <td height="30" bgcolor="ECF4FD" class="tableleft">&nbsp; 
             <input type="text" name="orgname" id="orgname" style="width:40%" class="table" value="" 

readonly="readonly"/>
             <input type="hidden" name="orgid" id="orgid"  value=""/>
		     <input type="button" class="botton02" value="选择" onclick="selectorgAll();"/>
            </td>
          </tr>
---------------------------------
 <tr> 
            <td  width="15%" height="30" bgcolor="ECF4FD" class="tablex">
                <div align="right">公文类别&nbsp;</div>
            </td>
            <td  width="55%" height="30" bgcolor="ECF4FD" class="tableleft">&nbsp; 
              <div id="good" style="display:none">
              </div>
              <div id="goods" style="display:none">
              </div>
            </td>
</tr>






简化版简化版简化版简化版简化版简化版简化版简化版简化版简化版简化版简化版

---------------------------------------------------------------
<%@ page language="java"
	import="java.util.*,com.hxkj.commonbusiness.MissiveCombiz.MissiveTypeCombiz,com.hxkj.entity.*"%>
<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.*"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ include file="../common/taglibs.jsp"%>
<html:html>
<%
	String id = "-1";
		if (request.getAttribute("id") != null) {
			id = (String) request.getAttribute("id");
		}
		String path = request.getContextPath();
		//获取公文类别
		MissiveTypeCombiz misCom = new MissiveTypeCombiz();
		List<MissiveTypeBean> MissiveTypeBeans = misCom
				.getMissiveTypeByScope("-1");//全部,包含司发文和部门文
		pageContext.setAttribute("MissiveTypeBeans",MissiveTypeBeans);
		Date temp = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		String tempStr = sdf.format(temp);
%>
<head>
	<link rel="stylesheet" href="<%=path%>/css/gcoa/css.css">
	<script language="Javascript" src="../../js/ortfunc.js">
</script>
	<script language="Javascript" src="../../js/ortfunct.js">
</script>
	<script language="Javascript" src="../../js/public.js">
</script>
	<!-- 选择部门时需要引入这两个js,从书中获取部门名称以及ID -->
	<script type="text/javascript" src="<%=path%>/js/jquery.js">
</script>
	<script type="text/javascript" src="<%=path%>/js/user.js">
</script>
	<style type="text/css">
.xian {
	border-bottom: 1px none;
	border-left: 1px none;
	border-top: 1px none;
	border-right: 1px none;
	text-align: left;
	font-size: 14px;
	background-color: ECF4FD;
}
</style>
	<SCRIPT language="javascript">
function saveMissiveNo(){
var isTrue = true;
var missiveType=document.getElementById("missiveType").value;
var orgid=document.getElementById("orgid").value;
var year=document.getElementById("year").value;
var typeScope=document.getElementById("typeScope").value;//公司:不提示选择部门
if (typeScope == "") {
    alert( "请选择所属类型!" );
    document.forms[0].typeScope.focus();
   isTrue=false;  
  }else if(document.forms[0].orgname.value==""&&typeScope!="0"){
      alert('请选择部门');
    document.forms[0].orgname.focus();
   isTrue=false;  
  }else if(document.forms[0].missiveType.value == "") {
		alert('请选择公文类别');
		document.forms[0].missiveType.focus();
		isTrue=false;  
  }else if(document.getElementById("dealType").value == ""&&document.getElementById("new").checked) {
		alert('请选择处理类型');
		document.forms[0].dealType.focus();
		isTrue=false;  
  }
if(isTrue){
 saveMissiveNoAjax(missiveType,orgid,year);
 document.forms[0].submit();
 //新增成功之后重新返回addMissiveNo.jsp页面
}
}
function saveMissiveNoAjax(x,y,z)
 {
 var xmlHttp;
 try
    {
   // Firefox,Opera 8.0+,Safari
    xmlHttp=new XMLHttpRequest();
    }
 catch (e)
    {

  // Internet Explorer
   try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
   catch (e)
      {

      try
         {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
      catch (e)
         {
         alert("您的浏览器不支持AJAX!");
         return false;
         }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
         document.myForm.time.value=xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET","<%=path%>/pages/MissiveNoManager/index.do?doaction=saveMissiveNo&missiveType="+x+"&orgid="+y+"&year="+z,true);//xz修改,针对ie8正文被锁bug
    xmlHttp.send(null);
 }
 function  doChange(f)
{
   if(f.value ==0)
   {
       document.getElementById("div").style.display="none";
       document.getElementById("good").style.display="block";
       document.getElementById("choice").style.display="block";
   }else if(f.value ==1){
      document.getElementById("div").style.display="block";
      document.getElementById("good").style.display="block";
      document.getElementById("good").value="";
      document.getElementById("choice").style.display="block";
   }
   else{
      document.getElementById("div").style.display ="block";
      document.getElementById("good").style.display="none";
      document.getElementById("good").value="";
           
   } 
}
function getMissiveType(){
var typeScope=$('#typeScope').val();
if(typeScope==""){
 document.getElementById("choice").style.display="none";
}
$.ajax({
type:"POST",success:function(data){
var len=data.length;
$('#good').contents().remove();
//for循环
for(i=0;i<len;i++){
$('#good').append("<input type='checkBox' name='missiveType' id='" + data[i].MISSIVE_TYPE_ID + " ' value='" + data[i].MISSIVE_TYPE_ID + "'/>" + data[i].NAME);
}
//for循环结束
}
});
}
function selfMissiveType(){
if(document.getElementById("new").checked){
     document.getElementById("div3").style.display="block";
}
if(document.getElementById("old").checked){
     document.getElementById("div3").style.display="none";
}
}
</SCRIPT>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	<form name="form" method="post"
		action="<%=path%>/pages/missiveManage/addMissiveNo.jsp" target="_self">
		<input type="hidden" name="id" value="<%=id%>" />
		<table width="98%" border="0" align="center" cellpadding="0"
			cellspacing="0" bgcolor="E9ECF5">
			<tr>
				<td height="26" colspan="2" valign="middle" class="font13">
					<div align="center">
						&nbsp;
					</div>
				</td>
				<td width="80%" height="26" valign="bottom" class="font13">
					<div align="right">
						<a href="javaScript:saveMissiveNo();" target="_self">保存</a>
						&nbsp;|&nbsp;
						<a href="<%=path%>/pages/missiveManage/MissiveNoManager.jsp"
							target="_parent">返回</a>
					</div>
				</td>
				<td width="3%" valign="top" class="font13">
					<div align="right">
						<img src="<%=path%>/img/gcoa/tddir0101.gif" width="17" height="14">
					</div>
				</td>
			</tr>
		</table>
		<table width="98%" border="0" align="center" cellpadding="0"
			cellspacing="0" bgcolor="E9ECF5">
			<tr>
				<td valign="top">
					<div align="center">
						<table width="95%" border="0" align="center" cellpadding="0"
							cellspacing="0" class="tablelsdi">
							<tr>
								<td width="4%" background="<%=path%>/img/gcoa/tablelb01.gif">
									<img src="<%=path%>/img/gcoa/tablelb01-left.gif" width="21"
										height="22">
								</td>
								<td width="82%" background="<%=path%>/img/gcoa/tablelb01.gif"
									class="font12w">
									新增公文字号
								</td>
								<td width="14%" background="<%=path%>/img/gcoa/tablelb01.gif">
									<div align="right">
										<img src="<%=path%>/img/gcoa/tablelb01-right.gif" width="21"
											height="22">
									</div>
								</td>
							</tr>
						</table>
						<table width="95%" border="0" align="center" cellpadding="0"
							cellspacing="0" class="tablelb">
							<tr>
								<td width="15%" height="30" bgcolor="E1EEFD" class="tablex">
									<div align="right">
										所属类型&nbsp;
									</div>
								</td>
								<td width="55%" height="30" bgcolor="E1EEFD" class="tableleft">
									&nbsp;
									<select name="typeScope" id="typeScope" style="width: 51%"
										onchange="doChange(this);getMissiveType()">
										<option value="" selected="selected">
											--请选择--
										</option>
										<option value="0">
											公司
										</option>
										<option value="1">
											部门
										</option>
									</select>
								</td>
							</tr>

							<tr id="div">
								<td height="30" bgcolor="ECF4FD" class="tablex">
									<div align="right">
										部门&nbsp;
									</div>
								</td>
								<td height="30" bgcolor="ECF4FD" class="tableleft">
									&nbsp;
									<input type="text" name="orgname" id="orgname"
										style="width: 40%" class="table" value="" readonly="readonly" />
									<input type="hidden" name="orgid" id="orgid" value="" />
									<input type="button" class="botton02" value="选择"
										onclick="selectorgAll();" />
								</td>
							</tr>
							<tr>
								<td height="30" bgcolor="E1EEFD" class="tablex">
									<div align="right">
										是否新公文类型&nbsp;
									</div>
								</td>
								<td height="30" bgcolor="E1EEFD" class="tableleft">
									&nbsp;
									<input type="radio" name="like" id="new" value="1"
										onclick="selfMissiveType(this)" />
									是
									<span style="padding-left: 20px;"></span>
									<input type="radio" name="like" id="old" value="0"
										onclick="selfMissiveType(this)" checked="checked" />
									否
								</td>
							</tr>
							<tr>
								<td width="15%" height="30" bgcolor="ECF4FD" class="tablex">
									<div align="right">
										公文类别&nbsp;
									</div>
								</td>
								<td width="55%" height="30" bgcolor="ECF4FD" class="tableleft">
									&nbsp;
									<div id="good" style="display: none">
									</div>
									<div id="choice" style="display: none">
										<font style="size: 5px;">可选操作:</font><span
											style="padding-left: 15px;"></span><a href="">全选</a><span
											style="padding-left: 25px;"></span><a href="">反选</a><span
											style="padding-left: 25px;"></span><a href="">取消</a>
									</div>
								</td>
							</tr>
							<tr id="div3" style="display: none">
								<td width="15%" height="30" bgcolor="E1EEFD" class="tablex">
									<div align="right">
										处理类型&nbsp;
									</div>
								</td>
								<td width="55%" height="30" bgcolor="E1EEFD" class="tableleft">
									&nbsp;
									<select name="dealType" id="dealType" style="width: 51%">
										<option value="" selected="selected">
											--请选择--
										</option>
										<option value="1">
											固定描述类型(年份)X号
										</option>
										<option value="2">
											年份第X期(总第N期)
										</option>
										<option value="3">
											部门+固定描述类型(年份)X号
										</option>
									</select>
								</td>
							</tr>

							<tr>
								<td height="30" bgcolor="ECF4FD" class="tablex">
									<div align="right">
										年度&nbsp;
									</div>
								</td>
								<td height="30" bgcolor="ECF4FD" class="tableleft">
									&nbsp;
									<input type="text" name="year" id="year"
										value="<%=tempStr + 6%>" readonly="readonly" class="xian">
								</td>
							</tr>
						</table>
						<br>
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html:html>
[/size][/align][size=x-large][b]----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 原文链接:https://www.f2er.com/ajax/161238.html

猜你在找的Ajax相关文章