gpt4 book ai didi

javascript - Jquery 输入段落生成器

转载 作者:行者123 更新时间:2023-12-03 04:17:16 25 4
gpt4 key购买 nike

我想构建一些可以接受用户输入的东西,例如段落编号,例如 5,然后当他们单击按钮时,它会生成该数量的段落?

我猜我可以在变量中存储一个段落,这没有问题,但不确定如何从用户输入中将其倍增:)

如果我得到一些开始的帮助和解释如何去做,我将不胜感激!

var $paragraph = $(
'<p> Tired of lorum Ipsum? why not try puff-puffing ipsum? A simple and fun
generator to help all those colour puffs that are in need. Put some puff into
your project.</p>'
});

最佳答案

抓取用户的值并使用for循环生成输出,然后将其放在页面上。

$("form").on("submit", function(e) {
e.preventDefault();
var num = $('#num').val(),
paragraph =
"<p>Tired of lorum Ipsum? why not try puff-puffing ipsum? A simple and fun generator to help all those colour puffs that are in need. Put some puff into your project.</p>",
output = '';
for (var i = 0; i < num; i++) {
output += paragraph;
}
$('#output').html(output);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="number" id="num">
<input type="submit" value="generate">
</form>

<div id="output"></div>

关于javascript - Jquery 输入段落生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44092352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com