2017-07-17 93 views
0

我已經嘗試了很多這裏發佈的與表單相關的解決方案(例如,阻止默認,更改表單屬性),但我似乎無法得到此工作。基本上,我已經開始使用兩個引導程序模板,到目前爲止它已經很好。我現在有一個文本框,我希望在第一個文本框中「提交」(即按回車)時添加另一個文本框。目前,第一個文本輸入被添加:按下javascript/HTML(引導)文本輸入上的輸入

$('#item').after(
        '<div class="form-group" onsubmit="return false"> <form class="form-horizontal" onSubmit="return false;"> </div><label for="exampleInputEmail1"> What was the value of the sale?</label><input type="text" class="form-control" id="InputSaleValue" placeholder="Enter value"><form onsubmit="return false"> <form action="javascript:void(-1)"> <small id="emailHelp" class="form-text text-muted">Excluding</small></div>' 

但此刻的頁面只是刷新,並帶我到這種形式我試圖生成的第一部分。

+0

請分享您的html和js文件並嘗試創建一個工作演示 – brk

+0

您是否需要一個文本框??或者每當用戶輸入一個鍵時添加一個新的文本框??如果它是一個文本框,那麼您可以使用它jQuery的隱藏和顯示功能,或者如果你需要多個文本框,你可以通過append方法添加它,讓我知道你的需要。 –

回答

0

我有這種模板。我在這裏發佈它,因爲也許你可以用它作爲墊腳石。只要運行代碼片段:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
 
<html> 
 
<table> 
 
    <tr> 
 

 
    <td><button type="button" id="button1" style="margin: 10px;">Add Textbox</button> 
 
    </tr> 
 
</table> 
 

 
</html> 
 
<script> 
 
    $("#button1").click(function() { 
 
    addRow(this); 
 
    }); 
 

 
    function addRow(btn) { 
 
    var parentRow = btn.parentNode.parentNode; 
 
    var table = parentRow.parentNode; 
 
    var rowCount = table.rows.length; 
 
    var row = table.insertRow(rowCount); 
 

 
    var cell1 = row.insertCell(0); 
 
    var element1 = document.createElement("input"); 
 
    element1.type = "text"; 
 
    element1.name = "text1"; 
 
    element1.className = "text1" 
 
    cell1.appendChild(element1); 
 
    } 
 
</script>

0

在這裏你去用一個例子液https://jsfiddle.net/37h6c1rs/

$('#item').append('<div class="form-group" onsubmit="return false"> <form class="form-horizontal" onSubmit="return false;"> </div><label for="exampleInputEmail1"> What was the value of the sale?</label><input type="text" class="form-control" id="InputSaleValue" placeholder="Enter value"><form onsubmit="return false"> <form action="javascript:void(-1)"> <small id="emailHelp" class="form-text text-muted">Excluding</small></div>'); 
 
     
 
$('#InputSaleValue').keypress(function(e){ 
 
    if (e.which === 13) { 
 
    $('#item').append('<div><input type="text id="addedTextbox /></div>') 
 
    } 
 
}); 
 
       
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="item"></div>

這可能不是你的精確解尋找,但這會幫助你達到目的地離子。