我添加了以下输入区域:
('#item').after('<div class="form-group" onsubmit="return false"></div><form action="javascript:void(-1)"><label for="exampleInputEmail1"> What?</label><input type="text" class="form-control" id="InputSaleValue" placeholder="Enter value"><small id="emailHelp3" class="form-text text-muted">eg 10%</small><form onsubmit="return false"> </div>');
按回车后,我有:
('#InputSaleValue').after('<div class="form-group" onsubmit="return false"></div><form action="javascript:void(-1)"><label for="exampleInputEmail1"> What?</label><input type="text" class="form-control" id="InputCommission" placeholder="Enter value"><small id="emailHelp3" class="form-text text-muted">eg 10%</small><form onsubmit="return false"> </div>');
但正在发生的事情是&#34;例如10%&#34;在第二次添加的底部添加两次,而不是分别添加到每次添加。
答案 0 :(得分:0)
它正在发生,因为在您的第二个代码行中,您在#InputSaleValue
之后添加了模板,而$('#item').after('<div class="form-group" onsubmit="return false"></div><form action="javascript:void(-1)"><div id="saleField"><label for="exampleInputEmail1"> What?</label><input type="text" id="InputSaleValue" class="form-control" placeholder="Enter value"><small id="emailHelp3" class="form-text text-muted">eg 10%</small></div></form onsubmit="return false"> </div>');
只是输入字段&amp;不是标签,例如10%。因此,您的内容就会出现在该字段的旁边。您可能希望将第一行更改为:
$('#saleField').after('<div class="form-group" onsubmit="return false"></div><form action="javascript:void(-1)"><label for="exampleInputEmail1"> What?</label><input type="text" class="form-control" id="InputCommission" placeholder="Enter value"><small id="emailHelp3" class="form-text text-muted">eg 10%</small><form onsubmit="return false"> </div>');
第二行为
div
在第一行中,我刚刚将该字段包含在内,包括标签,例如saleField
内的10,内容为import pandas as pd
import numpy as np
d=pd.DataFrame({' Label':['a','a','b','b'],'Count1':[10,20,30,40],'Count2':[20,45,10,35],
'Count3':[40,30,np.nan,22],'Nobs1':[30,30,70,70],'Nobs2':[65,65,45,45],
'Nobs3':[70,70,22,32]})
d
Label Count1 Count2 Count3 Nobs1 Nobs2 Nobs3
0 a 10 20 40.0 30 65 70
1 a 20 45 30.0 30 65 70
2 b 30 10 NaN 70 45 22
3 b 40 35 22.0 70 45 32
。在第二行,我只改变了选择器。以下是工作人员的链接:https://plnkr.co/edit/noxcWTmAaLwtYv8vx2CO?p=preview
答案 1 :(得分:0)
试试这个:
$(function(){
$('#item').after('<form action="javascript:void(-1)" class="form-group" id="formArea" onsubmit="return false"><div class="form-group"><label for="inputSaleValue"> What?</label><input type="text" class="form-control" id="inputSaleValue" placeholder="Enter value"><small class="form-text text-muted">eg 10%</small></div></form>');
$('#inputSaleValue').on('keydown',function(e){
if ((e.which == 13 || e.keyCode == 13) && $(this).val() != '') {
e.preventDefault();
$('#formArea').append('<div class="form-group"><label for="inputCommission"> What?</label><input type="text" class="form-control" id="InputCommission" placeholder="Enter value"><small class="form-text text-muted">eg 10%</small></div>');
}
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<div id="item"></div>
&#13;