如何在类似textarea的文本中显示禁用的文本 [英] How to have a disabled text in textarea-like

查看:71
本文介绍了如何在类似textarea的文本中显示禁用的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在文本区域内创建禁用/不可编辑的文本.我找到了使第一部分无法编辑的技巧 如何锁定文本区域的第一个单词? 但我的问题是在文本末尾加上它.但是它甚至可能不是文本区域的"html标记",但必须看起来像那样并且可编辑.

I'm trying to make a disabled/uneditable text inside a textarea. I've found a trick to have the first part uneditable here How to lock the first word of a textarea? but my problem is making it at the end of the text. But it may even not be a textarea "html-tag" but it must look like that and editable.

我已经研究和阅读了很多东西,其他人说只是在外面写,并告诉他们这些文字将被附加.但是,是的.那也是我的第一个主意.

I've researched and read a lot, others saying just write it outside and tell them this text will get appended. But yeah. That was my first idea as well.

是否有jQuery插件或执行此操作更简单的方法?

Is there a jQuery plugin or something easier to do this?

干杯!

在第一个评论后

我忘了提到我需要将不可编辑的文本更改为其他颜色,以便textarea不可能将其剪掉.

I forgot to mention that I need the uneditable-text to be of a different color so textarea wouldn't probably cut it off.

推荐答案

我有一些帮助,在这里 http://jsfiddle.net/index/tX44C/2/,已经通过使用contenteditable attr进行了大量工作.但是它仍然有一些缺陷,特别是在replaceWith触发时在Safari中,它失去了焦点.而且,我无法在IE浏览器上对其进行测试,我认为某些IE在"CSS内容"方面存在问题.

I have something kinda-working-here http://jsfiddle.net/index/tX44C/2/, been working on this a lot already making use of contenteditable attr. But it still has some defects particularly in Safari when the replaceWith triggers, it looses focus. And also, I can't test it on IE browsers, I think some IE have problems with "CSS content".

还有什么更好的吗?

修改: 我已经对上面发布的链接进行了一些更改(我也编辑了该链接),目前看来它工作得很好.我对此非常满意,因此除非有其他解决方案,否则我将立即使用它.

I've made a few changes to the link I posted above (I also edited the link) and it seems to work very fine for now. I'm quite contented with it so I'll be using this now unless some other solution presents itself.

说明: 小提琴上的代码还包括一个限制器和一些其他输入框,导致我正在查看contenteditable的内容.但是为了使文本在最后,我使用CSS的:aftercontent属性以及一些操作来删除br,同时在输入时将其保留在一边.

Clarification: The code on the fiddle also includes a limitter and some other input boxes cause I was viewing what the contenteditable was having. But in order to have the text on the end side, I used the CSS :after and content attribute and some manipulation to remove br's while typing to keep it on it's side.

干杯!

这篇关于如何在类似textarea的文本中显示禁用的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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