当前位置: 代码迷 >> Web前端 >> 点击文本框显示模式框,在方式框选中单选值,显示在文本框中
  详细解决方案

点击文本框显示模式框,在方式框选中单选值,显示在文本框中

热度:312   发布时间:2012-07-23 09:42:19.0
点击文本框显示模式框,在模式框选中单选值,显示在文本框中

如:jsp:

      <input class="i3" type="text" name="textfield" id='select4passer${index}'onclick='open_Dialog(this);' value="中国"/>

function open_Dialog(obj)
{
 var win = window.showModalDialog("country.jsp",window,"dialogWidth=425px;dialogHeight=300px;center=yes;status=no");
  if(win != null)
  {
    //document.getElementById("parentTextBox").value = win;
   // alert(obj.id);
    var str=win.split(";");
    if(str.length>0){
    // alert(str[0]);
     //赋值
     document.getElementById(obj.id+"hidden").value=str[1];
     document.getElementById(obj.id).value=str[0];
 
    }
  }
}

country.jsp:

                 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>请选择洲  和  国家</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
   <script src="javascript/jquery.1.3.2.js" type="text/javascript"></script>
   <style type="text/css">
   .table_main { border:none;font-size:12px; background:#f3f3f3; margin-left:14px;border-top:2px #f2f7ff solid;}
   .table_main td { border-left:1px solid #fff; border-bottom:1px solid #fff; text-align:left;width:100px;height:28px; line-height:28px;}
   #div1 { height:28px; lin-height:28px; text-align:left; padding-left:15px; margin-top:20px;}
   #div1 a {color:#09f; text-decoration:none;}
    #div1 a:hover { color:#f60;}
   </style>
  </head>
 
  <body onload="checkzhou(remen);">
  <input type="hidden" id="childTextBox"/>
 

  <div id="div1">
   <a href="javascript:void(0);"  id="remen" onclick="checkzhou(this);" >热门</a>&nbsp;&nbsp;
   <a href="javascript:void(0);" id="yzdyz" onclick="checkzhou(this);">亚洲大洋洲</a>&nbsp;&nbsp;
  <a href="javascript:void(0);" id="ozfz" onclick="checkzhou(this);" >欧洲非洲</a>&nbsp;&nbsp;
  <a href="javascript:void(0);" id="mz" onclick="checkzhou(this);">美洲</a>&nbsp;&nbsp;
  </div>
  <div id="show">
 
  </div>
   
  </body>
</html>

<script>
function  checkzhou(obj){
//alert(obj.id);
var str="<table border='0' id='table1' cellspacing='0' cellpadding='0' class='table_main'><tr>";
//根据不同洲 表格里面的内容不同
var arraycountry=new Array();
if(obj.id=="remen"){
arraycountry[0]=new Array('CN','中国','china','');
arraycountry[1]=new Array('FR','法国','amarea','');
arraycountry[2]=new Array('DE','德国','china','');
arraycountry[3]=new Array('IN','印度','amarea','');
arraycountry[4]=new Array('JP','日本','china','');
arraycountry[5]=new Array('KP','韩国','amarea','');
arraycountry[6]=new Array('MO','澳门','china','');
arraycountry[7]=new Array('HK','中国香港','amarea','');
arraycountry[8]=new Array('TW','中华台湾','china','');
arraycountry[9]=new Array('UK','英国','amarea','');
arraycountry[10]=new Array('US','美国','china','');
arraycountry[11]=new Array('TH','泰国','amarea','');
arraycountry[12]=new Array('RU','俄罗斯','china','');
arraycountry[13]=new Array('AU','澳大利亚','amarea','');
arraycountry[14]=new Array('BR','巴西','china','');
arraycountry[15]=new Array('CA','加拿大','amarea','');
arraycountry[16]=new Array('EG','埃及','china','');
arraycountry[17]=new Array('ID','印度尼西亚','amarea','');
arraycountry[18]=new Array('MY','马来西亚','china','');
arraycountry[19]=new Array('MX','墨西哥','amarea','');
arraycountry[20]=new Array('MO','蒙古','china','');
arraycountry[21]=new Array('NO','挪威','amarea','');
arraycountry[22]=new Array('PK','巴基斯坦','china','');
arraycountry[23]=new Array('PH','菲律宾','amarea','');
arraycountry[24]=new Array('SE','瑞典','china','');
arraycountry[25]=new Array('GH','瑞士','amarea','');
arraycountry[26]=new Array('AE','阿联酋','china','');
arraycountry[27]=new Array('SG','新加坡','amarea','');
arraycountry[28]=new Array('NL','荷兰','china','');
arraycountry[29]=new Array('NZ','新西兰','amarea','');
arraycountry[30]=new Array('VN','越南','china','');
}
//亚洲大洋洲
else if(obj.id=="yzdyz"){
arraycountry[0]=new Array('CN','中国','CHINA','');
arraycountry[1]=new Array('IN','印度','INDIA','');
arraycountry[2]=new Array('JP','日本','JAPAN','');
arraycountry[3]=new Array('KP','韩国','','');
arraycountry[4]=new Array('MO','澳门','','');
arraycountry[5]= new Array('NZ','新西兰','NEWZEALAND','');
arraycountry[6]=new Array('HK','中国香港','amarea','');
arraycountry[7]=new Array('TW','中华台湾','china','');
arraycountry[8]=new Array('TH','泰国','THAILAND','');
arraycountry[9]=new Array('PH','菲律宾','PHILIPPINES','');
arraycountry[10]= new Array('AU','澳大利亚','AUSTRLIA','');
arraycountry[11]=new Array('ID','印度尼西亚','INDONESIA','');
arraycountry[12]=new Array('MY','马来西亚','MALAYSIA','');
arraycountry[13]=new Array('MN','蒙古','MONGOLIA','');
arraycountry[14]=new Array('PK','巴基斯坦','PAKISTAN','');
arraycountry[15]=new Array('AE','阿联酋','china','');
arraycountry[16]=new Array('SG','新加坡','SINGAPORE','');
arraycountry[17]=new Array('KH','柬埔寨','CAMBODIA','');
arraycountry[18]=new Array('KR','朝鲜','','');
arraycountry[19]=new Array('IQ','伊拉克','IRAQ','');
arraycountry[20]=new Array('IR','伊朗','IRAN','');
arraycountry[21]=new Array('IL','以色列','ISRAEL','');
arraycountry[22]=new Array('KW','科威特','KUWAIT','');
arraycountry[23]=new Array('LA','老挝','LAOS','');
arraycountry[24]=new Array('MV','马尔代夫','MALDIVES','');
arraycountry[25]=new Array('NP','尼泊尔','NEPAL','');
arraycountry[26]=new Array('AF','阿富汗','AFGHANISTAN','');
arraycountry[27]=new Array('JO','约旦','JORDAN','');
arraycountry[28]=new Array('AZ','阿塞拜疆','AZERBAIJAN','');
arraycountry[29]=new Array('BD','孟加拉','BANGLADESH','');
arraycountry[30]=new Array('BH','巴林','BAHRAIN','');
arraycountry[31]=new Array('FJ','斐济','FIJIIS','');
arraycountry[32]=new Array('YE','也门','YEMEN','');
arraycountry[33]=new Array('TJ','塔吉克斯坦','TADZHIKISTAN','');
arraycountry[34]=new Array('QA','卡塔尔','QATAR','');
arraycountry[35]=new Array('OM','阿曼','OMAN','');
arraycountry[36]=new Array('LB','黎巴嫩','LEBANON','');
arraycountry[37]=new Array('VN','越南','VIETNAM','');
arraycountry[38]=new Array('KZ','哈萨克斯坦','KAZAKHSTAN','');
}
//美洲
else if(obj.id=="mz"){
arraycountry[0]=new Array('US','美国','UNITEDSTATES','');
arraycountry[1]=new Array('CA','加拿大','CANADA','');
arraycountry[2]=new Array('MX','墨西哥','MEXICO','');
arraycountry[3]=new Array('AR','阿根廷','ARGENTINA','');
arraycountry[4]=new Array('CL','智利','CHILE','');
arraycountry[5]=new Array('CO','哥伦比亚','COLOMBIA','');
arraycountry[6]=new Array('CU','古巴','CUBA','');
arraycountry[7]=new Array('GT','危地马拉','GUATEMALA','');
arraycountry[8]=new Array('CR','哥斯达黎加','COSTARICA','');
arraycountry[9]=new Array('UY','乌拉圭','URUGUAY','');
arraycountry[10]=new Array('BR','巴西','BRAZIL','');
arraycountry[11]=new Array('NI','尼加拉瓜','NICARAGUA','');
arraycountry[12]=new Array('PE','秘鲁','PERU','');
arraycountry[13]=new Array('VE','委内瑞拉','VENEZUELA','');
arraycountry[14]=new Array('PA','巴拿马','PANAMA','');
arraycountry[15]=new Array('JM','牙买加','JAMAICA','');
arraycountry[16]=new Array('HN','洪都拉斯','HONDURAS','');
arraycountry[17]=new Array('EC','厄瓜多尔','ECUADOR','');
arraycountry[18]=new Array('GD','格林纳达','GRENADA','');
arraycountry[19]=new Array('BS','巴哈马','BAHAMAS','');
arraycountry[20]=new Array('PY','巴拉圭','PARAGUAY','');
}
//欧洲非洲
else if(obj.id=="ozfz"){
arraycountry[0]=new Array('FR','法国','FRANCE','');
arraycountry[1]=new Array('DE','德国','GERMANY','');
arraycountry[2]=new Array('UK','英国','UNITED KINGDOM','');
arraycountry[3]=new Array('RU','俄罗斯','RUSSIA','');
arraycountry[4]=new Array('NO','挪威','NORWAY','');
arraycountry[5]=new Array('EG','埃及','EGYPT','');
arraycountry[6]=new Array('NL','荷兰','NETHERLANDS','');
arraycountry[7]=new Array('SE','瑞典','SWEDEN','');
arraycountry[8]=new Array('AT','奥地利','AUSTRIA','');
arraycountry[9]=new Array('BE','比利时','BELGIUM','');
arraycountry[10]=new Array('CZ','捷克','CZECHOSLOVAKIA','');
arraycountry[11]=new Array('DK','丹麦','DENMARK','');
arraycountry[12]=new Array('FI','芬兰','FINLAND','');
arraycountry[13]=new Array('GR','希腊','GREECE','');
arraycountry[14]=new Array('HU','匈牙利','HUNGARY','');
arraycountry[15]=new Array('IS','冰岛','ICELAND','');
arraycountry[16]=new Array('IE','爱尔兰','IRELAND','');
arraycountry[17]=new Array('IT','意大利','ITALY','');
arraycountry[18]=new Array('LT','立陶宛','LITHUANIA','');
arraycountry[19]=new Array('NA','摩洛哥','MOROCCO','');
arraycountry[20]=new Array('NG','尼日利亚','NIGERIA','');
arraycountry[21]=new Array('PL','波兰','POLAND','');
arraycountry[22]=new Array('PT','葡萄牙','PORTUGAL','');
arraycountry[23]=new Array('RO','罗马尼亚','ROMANIA','');
arraycountry[24]=new Array('SK','斯洛伐克','','');
arraycountry[25]=new Array('ZA','南非','SOUTHAFRICA ','');
arraycountry[26]=new Array('ES','西班牙','SPAIN','');
arraycountry[27]=new Array('KE','肯尼亚','KENYA','');
arraycountry[28]=new Array('GQ','赤道几内亚','EQUATORIAL GUINEA','');
arraycountry[29]=new Array('AO','安哥拉','ANGOLA','');
arraycountry[30]=new Array('BG','保加利亚','BULGARIA','');
arraycountry[31]=new Array('BI','布隆迪','BURUNDI','');
arraycountry[32]=new Array('BJ','贝宁','BENIN','');
arraycountry[33]=new Array('CC','刚果','CONGO','');
arraycountry[34]=new Array('CM','喀麦隆','CAMEROON','');
arraycountry[35]=new Array('DZ','阿尔及利亚','ALGERIA','');
arraycountry[36]=new Array('EE','爱沙尼亚','ESTONIA','');
arraycountry[37]=new Array('ET','埃塞俄比亚','ETHIOPIA','');
arraycountry[38]=new Array('GA','加蓬','GABON','');
arraycountry[39]=new Array('GH','加纳','GHANA','');
arraycountry[40]=new Array('GN','几内亚','GUINEA','');
arraycountry[41]=new Array('ZW','津巴布韦','ZIMBABWE','');
arraycountry[42]=new Array('UG','乌干达','UGANDA','');
arraycountry[43]=new Array('ZM','赞比亚','ZAMBIA','');
arraycountry[44]=new Array('TN','突尼斯','TUNISIA','');
arraycountry[45]=new Array('UA','乌克兰','UKRAINE','');
arraycountry[46]=new Array('SO','索马里','SOMALIA','');
arraycountry[47]=new Array('SD','苏丹','SUDAN','');
arraycountry[48]=new Array('RW','卢旺达','RWANDA','');
arraycountry[49]=new Array('MZ','莫桑比克','MOZAMBIQUE','');
arraycountry[50]=new Array('MU','毛里求斯','MAURITIUS','');
arraycountry[51]=new Array('MT','马耳他','MALTA','');
arraycountry[52]=new Array('ML','马里','MALI','');
arraycountry[53]=new Array('LV','拉脱维亚','LATVIA','');
}

var temp=arraycountry;
for(var j=0;j<arraycountry.length;j++){
text1=temp[j][1];
value1=temp[j][0];

var inner=temp[j][1]+";"+temp[j][0];
//创建radio 一行 8个
//能被4除
//alert(19 % 6.7);
if((j)%4==0){
str=str+"</tr><tr><td><input type='radio' name='radio1' id='radio1' value='"+inner+"' onclick='doPassToParent(this);'/>"+text1+"</td>";
}
//不能被4除 不换行
else{
str=str+"<td><input type='radio' name='radio1' id='radio1' value='"+inner+"' onclick='doPassToParent(this);'/>"+text1+"</td>";
}
}
str=str+"</table>";
$("#show").html(str);

}

 

function aa(obj){
alert("点击的值"+obj.value);
}

 document.getElementById("childTextBox").value = window.dialogArguments.document.getElementById("parentTextBox").value;
function doPassToParent(obj)
{
 //alert("点击的值"+obj.value);
 //if(document.getElementById("childTextBox").value.length <=0)
 //{
 // alert("请填写数据");
  //return;
 //}
 window.returnValue =obj.value ;
 window.close();

}

</script>

  相关解决方案