2015-05-11 67 views
-5

我有一個基於該值的輸入框,必須創建選擇標記。如何動態增加選擇標籤?

爲如:

如果我在輸入框中賦予值2,然後2選擇框已被創建

+5

你可以發佈什麼你已經嘗試到現在? –

+4

簡單的谷歌搜索將爲您提供100多種有用的方法 –

+0

問題完全缺乏細節。 – charlietfl

回答

1

這樣呢?

<input type="text" id="number" /><input type="button" value="GO" onclick="go()" /> 
<span id="selectBox"></span> 

<script> 
function go() 
{ 
    var number = $('#number').val(); 
    var selects = ''; 
    for(i = 0; i<number; i++) 
    { 
     selects += '<select></select>'; 
    } 
    $('#selectBox').html(selects); 
} 
</script> 
0

試試這個,讓我知道,如果這是你想要

<form method="post"> 
 
<input type="text" name="input" /> 
 
<input type="submit" name="sub" /> 
 
</form> 
 
<?php 
 
if(isset($_POST['sub'])){ 
 
\t $i=0; 
 
\t 
 
\t \t while($i<$_POST['input']){ 
 
\t \t \t ?> <select name="select_box<?php echo $i; ?>"> 
 
      \t <option>a</option> 
 
       <option>b</option> 
 
      </select><?php 
 
\t \t $i++; \t 
 
\t } 
 
} 
 
    
 
?>

0

什麼開始與你可以試試這個代碼:

<input type="number" id="n"/> 
<button id="btn" onclick="fn()">Click</button> 
<div id="d"></div> 
<script> 
function fn(){ 
    var len=parseInt(document.getElementById("n").value); 
    for(var i=0;i<len;i++){ 
    var ele = document.createElement("select"); 
    document.getElementById("d").appendChild(ele); 
    } 
} 
</script>