我使用jquery.colorfy https://github.com/cheunghy/jquery.colorfy来更改textarea中的关键字颜色。
我可以设置使用值$('#textarea').text("value");
来更改我的textarea值。
问题是:在代码之后$('#textarea').colorfy("markdown");
,命令:$('#textarea').text("value");
已死。
有人可以告诉我发生了什么事吗?非常感谢。
尝试这样:
$(document).ready(function(){
$('#area').colorfy("markdown");
$('#area').text("value");//will be hidden you can see by inspecting the html
$('.area').html("value");// will be visible to you
});
注意:我从示例中看到的是将display:none设置为textarea,但是creates a div with the same class which is the class of text area
将它们自己的CSS应用于这些文本区域。
$(document).ready(function(){
$('#area').colorfy("markdown");
$("#click").click(function(){
$('.area').html("value");// will be visible to you
});
});
.area {
float: auto;
margin-left: auto;
margin-right: auto;
width: 200px;
max-width: 200px;
height: 200px;
border-color: black;
border-width: 2px;
border-style: solid;
padding: 8px;
font-size: 15px;
text-align: left;
}
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="http://cheunghy.github.io/jquery.colorfy/jquery.colorfy.js"></script>
<script type="text/javascript" src="http://cheunghy.github.io/jquery.colorfy/jquery.colorfy.markdown.js"></script>
<textarea id="area" class="area">
hi
</textarea>
<button id="click">click!</button>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句