通过点击PHPAdmin来改变元素
Change element by click like PHPAdmin
我是js初学者。我想做一个编辑器像PHPAdmin。当单击其表时,该字段将更改为文本区域。当单击文本区域以外的其他位置时,它将变回文件并执行sql.
以下是我想用jQuery写的东西,我完全不明白我应该如何进一步编码,请建议。
$('#editor #gird_edit').bind({
click: function() { //When Click
var content = $(this).text(); // read what is in the filed
$("#gird_edit").text('<textarea>'+a+'</textarea>'); // This is not work, will only add html code,not change to text-area
},
/* ??? */: function() { //Outside click of the text-area
var content = $(this).text(); // read what is in the text-area
$("#gird_edit").text(????); // change back to the filed
}
})
Html <div id='editor'>
<div id='gird_edit'>hallo world</div>
<div id='gird_edit'>hallo world 2</div>
<div id='gird_edit'>hallo world 3</div>
</div>
我只有3个声誉,昨天才加入…很抱歉,我不能投票给你,因为这需要15个声誉。但是,我会非常感谢你的帮助!!
如果您想检测元素外部的点击,只需在整个页面上检测它们,并丢弃任何来自元素内部的点击。换句话说:
$('body').on('click', : function(e) { //Outside click of the text-area
if ($(this).parents().is('#gird_edit')) return false;
var content = $('textarea').text(); // read what is in the text-area
$("#gird_edit").text(????); // change back to the filed
});
然而,这听起来像你真正寻找的是一个"模糊"处理程序,这将触发每当有人在一个文本区域内,只是离开它;你可以用创建点击处理程序的基本方法来创建其中一个:
$('#gird_edit textarea').bind({
blur: function() {
// do the reverse of the click handler
}
相关文章:
- innerHTML赢得't改变元素
- 这是关于Jquery/JS的,如果我改变元素's HTML-我可以对它执行其他Jquery/JS操作吗
- 为什么硒会改变元素's href
- 如何通过jQuery点击另一个元素来改变元素的类
- 悬停在元素上改变元素,然后在悬停中包含该元素
- 在动画开始时改变元素高度(Angular)
- 如何改变元素"this"在jQuery
- 使用jQuery切换类和改变元素的大小
- 使用javascript使用2个标识符改变元素的宽度
- 点击改变元素位置
- 在不改变元素大小的情况下放大元素
- JQuery可拖动改变元素开始
- 改变元素的类
- 根据可滚动内容的样式改变元素样式
- jQuery offset()或position() -当元素靠近另一个元素时改变元素的属性
- 如何使用jquery每隔5秒改变元素的背景颜色
- jQuery .detach()不工作时,试图改变元素的位置沿DOM滚动
- 当我点击元素A时,我想改变元素B的文本
- 如何在JavaScript中编写hoverHandler来改变元素悬停时的颜色
- 使用jQuery改变元素顺序的最优方法