【问题标题】:How to generate line number for each line text? [duplicate]如何为每行文本生成行号? [复制]
【发布时间】:2019-11-30 05:21:05
【问题描述】:

我正在尝试制作行号生成器工具。当任何人在 Textarea 中写入一些行并单击“添加行号”按钮时,所有行都会获得序列号。我不知道该怎么做,只是分享结构代码。请帮忙,在此先感谢。

<html>
<body>
<form>

  <textarea autocomplete="off" cols="30" id="TextInput" name="message" rows="25" style="display: block;margin-left: auto;margin-right: auto;width: 70%;"></textarea>
  <br />  

</form>

<input id="AddLineNumber" onclick="myFunction()" style="display: block;margin-left: auto;margin-right: auto;color: black;" type="button" value="Add Line Number!" /><br />

<script>
function myFunction() {

}
</script>

</body>
</html>

【问题讨论】:

  • 我正在尝试制作行号生成工具....代码在哪里?
  • 您的输入和预期输出是什么?
  • @SBimochan 输入:AppleBannana 那么输出应该是 1)Apple2)Banana

标签: javascript html css


【解决方案1】:

这是您需要的,在功能上我们将使用 jquery,因此添加一个包含 jquery.Regards 的链接。

<html>

<style>

.expand {
    height: 1em;
    width: 50%;
    padding: 3px;
}

</style>
<body>
<form>

  <textarea class="expand" autocomplete="off" cols="30" id="TextInput" name="message" rows="25" style="display: block;margin-left: auto;margin-right: auto;width: 70%;"></textarea>
  <br />  

</form>

<input id="AddLineNumber" onclick="myFunction()" style="display: block;margin-left: auto;margin-right: auto;color: black;" type="button" value="Add Line Number!" /><br />

<script>
function myFunction() {
    $('textarea.expand').focus(function () {
    $(this).animate({ height: "4em" }, 500);
});
}
</script>

【讨论】:

  • 您忘记添加 headbody 部分.. 所以您的 html 根本无效 - 您还提到了 jqeuy,但您没有包含相关脚本
  • 伙计,我刚刚复制了你的代码并在上面编辑,所以你应该添加你想要的其他东西。
  • .. 我刚刚复制了您的代码... 这不是我的代码。如果您想正确回答问题,那么您需要向社区提供有效的答案 - 您可以edit您的答案并将缺少的信息添加到其中
猜你喜欢
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 2020-10-13
  • 2017-04-03
  • 2018-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多