HTML / JavaScript:如何制作< textarea>的默认文字不可删除? [英] HTML/JavaScript: How to make default text of a <textarea> undeletable?

查看:700
本文介绍了HTML / JavaScript:如何制作< textarea>的默认文字不可删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让用户的< textarea> 输入的默认文本变得不可删除?例如,如果我们有这样一个< textarea> ,那么:

< textarea>我喜欢/不喜欢这个网站,因为< / textarea>



用户应该能够完成我喜欢/因为句子,但从来没有能够删除这部分。



我知道这个问题有更简单的方法,但我被要求这样做。此外,目标网站使用原型JavaScript框架,因此它必须涉及原型或没有框架。 jQuery无法使用,因为它会导致与原型的冲突。



非常感谢您的提前。

解决方案


$ b

您可以使它看起来像是textarea的一部分,即使它不是。 .net / eAW2U /rel =noreferrer>简单的jsfiddle示例来演示这个想法


Is there a way to make the default text of a <textarea> input become undeletable by the user? For example, if we had a <textarea> like this:

<textarea>I like/dislike this site because</textarea>

The user should be able to complete the "I like/dislike this site because" sentence but never be able to remove this part.

I understand there are easier approaches for this problem, but I've been asked to do it this way. Also, the target website uses prototype javascript framework so it must either involve prototype or no framework. jQuery cannot be used as it would cause conflict with prototype.

Many thanks in advance.

解决方案

You could make it look like it's part of the textarea, even if it is not.

Simple jsfiddle example to demonstrate the idea

这篇关于HTML / JavaScript:如何制作&lt; textarea&gt;的默认文字不可删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆