Javascript 单击某个位置时添加事件
我正在开发一个简单的管理系统。现在我想让管理员更容易编辑数据。我的目标是,当双击一个元素时,它将变为输入。编辑之后,如果管理员在输入之外单击,它将运行一个事件来运行ajax。这就像PHPMyAdmin中的系统,当我们想要编辑数据时,只需双击数据 HTML 但我不知道当管理员在输入之外单击时,如何生成一个事件来执行Ajax。有人能帮我吗?还是说已经有了功能Javascript 单击某个位置时添加事件,javascript,html,jquery,ajax,codeigniter,Javascript,Html,Jquery,Ajax,Codeigniter,我正在开发一个简单的管理系统。现在我想让管理员更容易编辑数据。我的目标是,当双击一个元素时,它将变为输入。编辑之后,如果管理员在输入之外单击,它将运行一个事件来运行ajax。这就像PHPMyAdmin中的系统,当我们想要编辑数据时,只需双击数据 HTML 但我不知道当管理员在输入之外单击时,如何生成一个事件来执行Ajax。有人能帮我吗?还是说已经有了功能 ***注意:我想在标记锚上排除它。因此,当按下某个链接时,它不会执行Ajax,而是转到该链接。使用输入元素的onblur事件。当用户焦点从输入
***注意:我想在标记锚上排除它。因此,当按下某个链接时,它不会执行Ajax,而是转到该链接。使用输入元素的onblur事件。当用户焦点从输入字段移出时,它将触发。使用输入元素的onblur事件。当用户焦点从输入字段中移出时,它将触发。因为您使用的是jQuery,所以要钩住模糊事件,如下所示:
$(".editable").dblclick(function () {
const id = $(this).data("id");
const col = $(this).attr("name");
$(this).html(
"<form>
<input class="editing" type='text' value='" + $(this).val() + "'>
</form>"
);
// use more specific targets here, i just use the class of the input
// you should use the same $(this) content in the end
$('.editing').blur(function() {
$.ajax({
url: "http://localhost/myProject/myController/myMethod",
type: "post",
data: {
id: id,
col: col,
value: $('.editing').val()
},
success: function () {
document.location.href = "http://localhost/myProject/myController";
},
});
});
});
当附加到模糊事件的元素失去焦点时,会触发模糊事件,但不会因冒泡而触发,仅针对特定元素
查找更多信息,或者可能,因为您使用的是jQuery,所以钩住模糊事件,如下所示:
$(".editable").dblclick(function () {
const id = $(this).data("id");
const col = $(this).attr("name");
$(this).html(
"<form>
<input class="editing" type='text' value='" + $(this).val() + "'>
</form>"
);
// use more specific targets here, i just use the class of the input
// you should use the same $(this) content in the end
$('.editing').blur(function() {
$.ajax({
url: "http://localhost/myProject/myController/myMethod",
type: "post",
data: {
id: id,
col: col,
value: $('.editing').val()
},
success: function () {
document.location.href = "http://localhost/myProject/myController";
},
});
});
});
当附加到模糊事件的元素失去焦点时,会触发模糊事件,但不会因冒泡而触发,仅针对特定元素
查找更多信息,或者,模糊是否可以为锚定标记设置例外?您所说的为锚定设置例外是什么意思??我不知道你想如何处理它们,但关键是要了解你正在使用的选择器和你拥有的元素。解释得再清楚一点,我也许能帮得更多一点我明白了,我已经得到了我想要的东西。模糊能为锚标签破例吗?你说为锚破例是什么意思??我不知道你想如何处理它们,但关键是要了解你正在使用的选择器和你拥有的元素。解释得再清楚一点,我也许能帮上更多的忙。我明白了,我已经得到了我想要的
public function myMethod()
{
$id = $this->input->post("id");
$col = $this->input->post("col");
$value = $this->input->post("value");
$this->db->set($col, $val);
$this->db->where('id', $id);
$this->db->update("my_table");
}
$(".editable").dblclick(function () {
const id = $(this).data("id");
const col = $(this).attr("name");
$(this).html(
"<form>
<input class="editing" type='text' value='" + $(this).val() + "'>
</form>"
);
// use more specific targets here, i just use the class of the input
// you should use the same $(this) content in the end
$('.editing').blur(function() {
$.ajax({
url: "http://localhost/myProject/myController/myMethod",
type: "post",
data: {
id: id,
col: col,
value: $('.editing').val()
},
success: function () {
document.location.href = "http://localhost/myProject/myController";
},
});
});
});