【发布时间】:2015-04-27 00:35:40
【问题描述】:
我正在尝试为我正在处理的项目提供文本编辑器,但在从文本区域中选择文本然后单击按钮将文本环绕在其周围时,我陷入了困境。
示例:
我会有一个按钮说Insert -,一旦单击并选择了文本
select me 会变成-select me-
这是我当前的 HTML (jsfiddle mirror):
<div class="container wrapper">
<form class="create post" method="post" action="action.php?a=createPost">
<h1>Create a Post</h1>
<input name="title" type="text" placeholder="Title" autocomplete="off" autofocus="autofocus" maxlength="100" required/>
<textarea name="introduction" placeholder="Introduction" maxlength="255"></textarea>
<ul class="options">
<li><p>Article Edits:</p></li>
<li>
<a class="fa fa-italic" trigger="italic">icon-placeholder</a>
</li>
</ul>
<textarea name="content" placeholder="Article" required="required"></textarea>
<input type="submit" value="Submit for Review" />
</form>
</div>
这是我当前的 CSS:
form.create.post {
height:auto;
overflow:auto;
}
form.create.post > h1 {
font-weight:800;
font-size:46px;
letter-spacing:-5px;
text-transform:uppercase;
}
form.create.post > input,
form.create.post > textarea {
display:block;
margin:0 0 5px;
padding:5px 10px;
border:solid 1px #CCC;
border-radius:2px;
}
form.create.post > input[name=title] {
width:50%;
}
form.create.post > input[type=submit] {
width:25%;
background-image:linear-gradient(#F7F7F7,#E7E7E7);
}
form.create.post > textarea {
width:calc(100% - 22px);
}
form.create.post > textarea[name=content] {
height:300px;
}
/*-- text editor --*/
form.create.post > ul {
height:auto;
overflow:auto;
margin-bottom:5px;
list-style-type:none;
}
form.create.post > ul > li {
display:inline-block;
}
form.create.post > ul > li > p {
padding:5px;
}
form.create.post > ul > li > a {
display:block;
padding:5px;
cursor:pointer;
}
我不知道从哪里开始使用 javascript。
【问题讨论】:
-
@LShetty,这是很久以前写的,也许有一个jQuery方法? - 这似乎也不适用于
textrea -
不,没有,因为 jQuery 只是 JS 的包装器。
-
不简单为:text = char + " " + text + " " + char; ?
-
@ManuelBitto 我已经说过
I have no idea where to start with the javascript for this.
标签: javascript jquery html