从input中添加select option

本文介绍了一个用于设定配达时间的网页界面实现方法,包括最小配达日输入验证及时间选项的动态生成等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>配達希望時間設定</title>
<style>
.btn 
{
 BORDER-RIGHT
: #7b9ebd 1px solid;
     PADDING-RIGHT
: 2px;
     BORDER-TOP
: #7b9ebd 1px solid;
     PADDING-LEFT
: 2px;
     FONT-SIZE
: 12px;
 FILTER
: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
     BORDER-LEFT
: #7b9ebd 1px solid;
     CURSOR
: hand;
     COLOR
: black;
     PADDING-TOP
: 2px;
     BORDER-BOTTOM
: #7b9ebd 1px solid
}

</style>

<script language ="javascript">
/*
*optionリストを形成します
*/

function displayOptionList() {
    
var listTableObj = document.getElementById("listSel");
    
var listTableInnerHtml="";
    
for (var i=0;i<ary.length;i++){
        
var oneTalbeInnerHtml = oneRecord;
        oneTalbeInnerHtml 
= oneTalbeInnerHtml.replace("@@@option_text@@@",ary[i].text);
        oneTalbeInnerHtml 
= oneTalbeInnerHtml.replace("@@@option_value@@@",ary[i].value);
        listTableInnerHtml 
+= oneTalbeInnerHtml;
    }

    listTableInnerHtml 
= blankSelect.replace("@@@sel_options@@@",listTableInnerHtml );
    listTableObj.innerHTML
=listTableInnerHtml;    
}





/*oS(String):源input的id
  *oT(String):目標select的id
  
*/

function moveSelect(oS,oT){
    oS
=document.getElementById(oS);
    oT
=document.getElementById(oT);
    
if(oS.value==""){
        alert(
"指定の時間を書き込んで下さい.");
    }
else{
        
var i =oT.options.length;
        oS.value
=oS.value.replace(/(^s+)|(s+$)/g,'');
        
var opt=new Option(oS.value,oS.value,false,false)  
        oT.options[oT.options.length]  
=  opt  
        i
++;      
        oS.value
="";
    }

}

/*o(String):制御されたselectのid
  *p(Long):移動する目標の位置
  
*/

function moveTo(o,p){
    o
=document.getElementById(o);
    start
=o.selectedIndex;
    
var isUp=1;
    
if (p<start)
        isUp
=-1;
    
if (p<0)
        p
=0;
    
if (p>=o.options.length)
        p
=o.options.length-1;
    
if (start==-1)
        
return false;
    
if (p==start)
        
return false;
    
for (var i=start;i*isUp<p*isUp ;i=i+isUp )
        o.options[i].swapNode(o.options[i
+isUp]);
}

/*o(String):制御されたselectのid
  *id(Long):optinの索引
  
*/


function delOption(o,id){
    o
=document.getElementById(o);
    
//alert(o+"/"+id);
    if(id >= 0){
            o.options.remove(id);
            lastOptionOnFocus(o,o.options.length
-1);
        }
else{
            
return;
        }

}

/*
*使用options集合中最皇后一取焦点
*/

function lastOptionOnFocus(o,index){
           o.selectedIndex 
= index;
}

/*
*
*/

function doTimeCheck(){
    
var tempValue=document.viewForm.MIN_TIME.value;
    
if(tempValue==""){
        alert(
"最小配達日を入力して下さい.");
        document.viewForm.MIN_TIME.focus();
    }
else{
        
if(/^-?d+(.d+)?$/.test(tempValue))
            tempValue
=parseInt(tempValue); 
            
if (confirm("入力この最小配達日を確認しますか?")){
                document.viewForm.MIN_TIME.value
=document.viewForm.MIN_TIME.value.replace(/(^s+)|(s+$)/g,'');
                
//document.viewForm.action="S010501.htm";
                //document.viewForm.submit();
            }
else{    
                document.viewForm.MIN_TIME.focus();
                
return;
            }

        }
else{
            alert(
'正しい最小配達日を入力して下さい.'); 
            document.viewForm.MIN_TIME.value
="";
            document.viewForm.MIN_TIME.focus();
            
return;
        }

    }

}

</script>

</head>
<body onload="bodyOnload()"><form name="viewForm" method="post">
        
<table style="border: 2px solid rgb(1, 90, 180); font-size: 10pt;" width="700">
            
<tbody><tr>
                
<td>
                    
<table style="color: white; font-size: 11pt; font-weight: bold;" bgcolor="#015ab4" width="100%">
                        
<tbody><tr>
                            
<td>配達希望時間設定</td>
                        
</tr>
                    
</tbody></table>    
                
</td>
            
</tr>
            
<tr>
                
<td>
                    
<table border="0" width="100%">
                        
<tbody><tr>
                            
<td style="border: 1px solid rgb(1, 90, 180); color: rgb(1, 90, 180); font-size: 10pt; font-weight: bold;" align="center" width="150">最小配達日指定</td>
                            
<td colspan="4" style="font-size: 10pt;"><input id="MIN_TIME" name="MIN_TIME" size="25" onkeydown="if(event.keyCode==13)event.keyCode=9" type="text">&nbsp;&nbsp;日後より可能</td>
                        
</tr>
                        
<tr height="5"><td><br></td></tr>
                        
<tr>
                            
<td style="border: 1px solid rgb(1, 90, 180); color: rgb(1, 90, 180); font-size: 10pt; font-weight: bold;" align="center" width="150">配達指定時間</td>
                            
<td style="font-size: 10pt;" valign="top" width="150"><input name="s1" id="s1" size="25" onkeydown="if(event.keyCode==13)event.keyCode=9" type="text"></td>
                            
<td align="center" valign="top" width="50"><input class="btn" onclick="moveSelect('s1','s2')" value=" -&gt; " type="button"></td>
                            
<td width="200">
                            
<div id="listSel">
                            
<select name="s2" id="s2" size="10" multiple="multiple" style="width: 100%;"></select>
                            
</div>
                            
<br></td>
                            
<td>
                                
<table align="center" width="80%">
                                    
<tbody><tr><td><input class="btn" onclick="moveTo('s2',0)" value="∧" type="button"></td></tr>
                                    
<tr><td><input class="btn" onclick="moveTo('s2',document.getElementById('s2').selectedIndex-1)" value="▲" type="button"></td></tr>
                                    
<tr><td><input class="btn" onclick="delOption('s2',document.getElementById('s2').selectedIndex)" value="×" type="button"></td></tr>
                                    
<tr><td><input class="btn" onclick="moveTo('s2',document.getElementById('s2').selectedIndex+1)" value="▼" type="button"></td></tr>
                                    
<tr><td><input class="btn" onclick="moveTo('s2',document.getElementById('s2').options.length-1)" value="∨" type="button"></td></tr>
                                
</tbody></table>
                            
</td>
                        
</tr>
                        
<tr height="5"><td><br></td></tr>
                        
<tr>
                            
<td colspan="5" style="border: 1px solid rgb(1, 90, 180); color: rgb(1, 90, 180); font-size: 10pt; font-weight: bold;" align="center">
                                
<input class="btn" value="更新" style="width: 90px;" onclick="doTimeCheck()" type="button">
                            
</td>
                        
</tr>                    
                    
</tbody></table>
                
</td>
            
</tr>
        
</tbody></table>
        
</form></body></html>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值