HTML 文本区域部分可编辑

发布于 2025-01-13 11:50:47 字数 876 浏览 2 评论 0原文

我希望 textarea 能够部分编辑。第一列应该是不可编辑的,第二列应该是用户输入这个“答案”的地方。

第一列是人们早起、深夜和晚上的情况,之后的所有内容用户应该能够插入,之前的所有内容都应该是只读的。

该脚本仅适用于内联文本,但我的文本应该是 row1、row2 和 row3,但我不知道该怎么做。

$('#people').keydown(function() {
  if ($(this).val().indexOf('people early: 
      people late:
      people night: ') !== 0) {
    var length = "This is constant.  ".length;
    var current = $(this).val();
    var after = current.slice(length);

    $(this).val("This is constant.  " + after);
  }
});
<textarea id="people">
     people early: 
     people late:
     people night:
    </textarea>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

I want a textarea to be partially editable. The first column should be not editable and the second should be the place where the user will input this "answer".

The first column is people early, late and night and everything after that the user should be able to insert and everything before should readonly.

The script is only working for inline text but my text should be row1, row2 and row3 and I do not know how do it.

$('#people').keydown(function() {
  if ($(this).val().indexOf('people early: 
      people late:
      people night: ') !== 0) {
    var length = "This is constant.  ".length;
    var current = $(this).val();
    var after = current.slice(length);

    $(this).val("This is constant.  " + after);
  }
});
<textarea id="people">
     people early: 
     people late:
     people night:
    </textarea>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2025-01-20 11:50:47

我假设您应该使用 3 个不同的输入来获取您想要的 3 个信息,然后格式化一个字符串以使其看起来像您想要的那样。

I assume you should use 3 different inputs to get the 3 information you want then format a string to makes it look how you want it to be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文