Javascript 使用div调整文本区域的大小
调整div中文本区域的大小时,如何调整div的大小Javascript 使用div调整文本区域的大小,javascript,jquery,Javascript,Jquery,调整div中文本区域的大小时,如何调整div的大小 如果我创建两个或多个粘滞并使用ESC,则所有粘滞都将关闭。如何设置ESC以仅关闭活动弹出窗口 如何在页面刷新时保持活动粘性 我使用此代码制作一个弹出式便笺: <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.2.js"></script> <script type="text/javascript" src="ht
<script type="text/javascript" src="https://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.8.18/jquery-ui.js"></script>
<script>
$(document).ready(function(){
function limitTextareaLine(e) {
if(e.keyCode == 13 && $(this).val().split("\n").length >= $(this).attr('rows')) {
return false;
}
}
$(function() {
$('textarea.limited').keydown(limitTextareaLine);
});
var x = "<div class='darkYellow'><div class='close'>X</div>Note<div class='lightYellow'><textarea maxlength='250' rows='8' cols='25' class='limited'></textarea></div></div>";
$('#click').click(function () {
$('#one').append('<div class="note">'+x+'</div>');
$( ".darkYellow" ).draggable();
$('.close').each(function(){
$('.close').click(function() {
$(this).parent().remove();
});
});
});
$('.darkYellow').live('click', function() {
$(this).addClass("index");
});
$('.darkYellow').live('blur', function() {
$(this).removeClass("index");
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
window.open(location, '_self', '');
openedWindow.close();
}
});
});
$(文档).ready(函数(){
功能限制文本区域线(e){
如果(e.keyCode==13&&$(this.val().split(“\n”).length>=$(this.attr('rows')){
返回false;
}
}
$(函数(){
$('textarea.limited').keydown(limitTextareaLine);
});
var x=“XNote”;
$('#click')。单击(函数(){
$('#一')。附加(''+x+'');
$(“.darkYellow”).draggable();
$('.close')。每个(函数(){
$('.close')。单击(函数(){
$(this.parent().remove();
});
});
});
$('.darkYellow').live('click',function(){
$(此).addClass(“索引”);
});
$('.darkYellow').live('blur',function(){
$(此).removeClass(“索引”);
});
$(文档).keyup(函数(e){
如果(e.keyCode==27){
窗口。打开(位置“_self”和“”);
openedWindow.close();
}
});
});
在CSS中,将父div的显示设置为display:table应该可以解决问题,并在更改textarea的大小时调整其大小 编辑:至于转义(刚刚刷新并看到了这一点),您可以使用document.activeElement,或者因为您使用的是jQuery,所以可以使用$(“:focus”)
编辑:将openWindow变量设置为
openWindow=$(':focus')
对于您添加的第三项,您必须将活动的sticky保存在页面的localstorage中,并在每次更改哪个sticky处于活动状态时对其进行更新。以下是有关localstorage的一些信息您可以使用jQuery的resize来捕获resize事件
$("textarea").resizable({
resize: function() {
//resize your div
}
});
对于便笺:如何定义变量openedWindow?将固定宽度和高度更改为最小宽度和最小高度,如下所示 它应该自动调整大小
*{
margin:auto;
padding:0;
}
.darkYellow {
position:absolute;
background-color: #76B5F0;
min-width:200px;
min-height:150px;
font-size:12px;
text-indent:1px;
-webkit-box-shadow: 1px 1px 10px #888888;
cursor:move
}
.lightYellow {
min-width:200px;
min-height:135px;
background-color: #8EC0EE;
margin-top:1px;
}
textarea {
background-color: #8EC0EE;
border: 0px;
}
.index {
z-index: 55;
}
.close {
width:7px;
height:7px;
padding:0;
line-height:2pt;
float:right;
margin-top:6px;
margin-right:4px;
font-size:14px;
cursor:pointer;
}
还可以使用JQuery的最新版本,我已经在下面更新了you fiddle
现在我们所能做的就是猜测,因此请发布一个最小的工作代码片段以获得最佳答案。我建议您在可拖动的
div
中添加一个调整大小功能,并让textarea
进行调整。这样,即使没有textarea
resize句柄的浏览器也可以调整大小!现在我必须尝试找到解决方案,以便在刷新页面时为任何粘性页面创建“活动会话”。这在IE中不起作用。即使Edge也不支持css调整大小。我建议使用jQueryUI的调整大小功能