我想要的行为--在页面上单击“单击我”,这会打开Toastr,并有一个文本框,用户在Toastr文本框中键入信息,然后单击"Append“,这会将Toastr文本框中的文本添加到页面中。
到目前为止,我可以从页面上的文本框中追加,也可以用带有附加按钮的textbox (使用页面中的相同代码)来做烤面包,但是我还没有弄清楚如何从烤面包圈中添加。
$(document).ready(function() {
$('#clickText').click(function() {
toastr["success"]('<div><input class="input-small" value="textbox" id="first-name"/> </div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="inPut" class="btn" style="margin: 0 8px 0 8px">Append</button></div>')
});
});
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": 0,
"extendedTimeOut": 0,
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut",
"tapToDismiss": false
}
$(document).ready(function() {
$('#inPut').click(function() {
var FLname = "<br>" +
$('#first-name').val() + " ";
$('#outPut').append(FLname);
});
}); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--Toastr Min CSS -->
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css'>
<!--Toastr Min JS -->
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js'></script>
<!--Script Links Above -->
<input type='text' maxlength="25" id='first-name' placeholder="First Name">
<button type="button" id="inPut" class="btn" style="margin: 0 8px 0 8px">Append</button>
</div>
<div id ="clickText"> Click Me! </div>
<div id='outPut'>
</div>
在输入中填写占位符名,然后点击框旁边的追加,将文本附加到页面,
点击“点击我!”短信,打开Toastr。-我还没让关闭按钮正常工作。
发布于 2019-05-25 11:23:19
当您单击clickText btn时,创建新的#inPut按钮,您需要为新按钮分配单击函数
试着改变这个
$(document).ready(function() {
$('#clickText').click(function() {
toastr["success"]('<div><input class="input-small" value="textbox" id="first-name"/> </div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="inPut" class="btn" style="margin: 0 8px 0 8px">Append</button></div>')
});
}); 至
$(document).ready(function() {
$('#clickText').click(function() {
toastr["success"]('<div><input class="input-small" value="textbox" id="first-name"/> </div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="inPut" class="btn" style="margin: 0 8px 0 8px">Append</button></div>')
$('#inPut').click(function() {
var FLname = "<br>" +
$('#first-name').val() + " ";
$('#outPut').append(FLname);
});
});
});确保删除- <input type='text' maxlength="25" id='first-name' placeholder="First Name">
从您的代码的另一部分(吐司之外的代码)
https://stackoverflow.com/questions/56304229
复制相似问题