點擊文本框顯示模式框,在模式框選中單選值,顯示在文本框中

如: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;}
   #p1 { height:28px; lin-height:28px; text-align:left; padding-left:15px; margin-top:20px;}
   #p1 a {color:#09f; text-decoration:none;}
    #p1 a:hover { color:#f60;}
   </style>
  </head>
 
  <body onload="checkzhou(remen);">
  <input type="hidden" id="childTextBox"/>
 
  <p id="p1">
   <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;
  </p>
  <p id="show">
 
  </p>
   
  </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>
作者:gdn_wolf

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。