#ai问答 副文本编辑器实现这种提示词填入,然后留有可编辑的内容,并且突出显示的 这种效果怎么实现

关注让 “紫雾凌寒” 来帮你回答,本回答结合 DeepSeek
如果还有问题,请评论或点击头像私信,如果有帮助到您, 请关注、采纳、点赞
<textarea>)。<!DOCTYPE html>
<html>
<head>
<style>
.prompt {
color: gray;
}
</style>
</head>
<body>
<textarea id="myTextarea">
这里是提示词 <span class="prompt">(可编辑)</span>
</textarea>
</body>
</html>
document.addEventListener('DOMContentLoaded', function () {
const textarea = document.getElementById('myTextarea');
const initialText = textarea.value;
const promptIndex = initialText.indexOf('(可编辑)');
const newText = initialText.slice(0, promptIndex) + initialText.slice(promptIndex + 6);
textarea.value = newText;
textarea.style.color = 'black';
});
希望以上解答对您有所帮助。如果您有任何疑问,欢迎在评论区提出。