HTML 文本区域部分可编辑
我希望 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您应该使用 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.