search
HomeWeb Front-endJS TutorialUse Jquery to implement editable tables and use AJAX to submit to the server to modify the data_jquery

The following is the js Code:
Copy the code The code is as follows:

$ (function() { // Equivalent to adding the onload event to the body tag in the page
$(".caname").click(function() { // Adding the click function to the tag with caname class in the page
var objTD = $(this);
var oldText = $.trim(objTD.text()); // Save the old category name
var input = $(""); // HTML code of the text box
objTD.html(input); // The content of the current td becomes the text box
// Set the text box The click event is invalid
input.click(function() {
return false;
});
// Set the style of the text box
input.css("border-width", "0px"); //The border is 0
input.height(objTD.height()); //The height of the text box is the height of the current td cell
input.width(objTD.width()) ; // The width is the width of the current td cell
input.css("font-size", "14px"); // The content text size of the text box is 14px
input.css("text-align ", "center"); // Center the text
input.trigger("focus").trigger("select"); // Select all
// When the text box loses focus, it changes back to text
input.blur(function() {
var newText = $(this).val(); // Modified name
var input_blur = $(this);
// As the old category The data submission operation is only performed when the name is different from the modified name
if (oldText != newText) {
// Get the ID (serial number) corresponding to the category name
var caid = $.trim (objTD.prev().text());
// AJAX asynchronously changes the database
var url = "../handler/ChangeCaName.ashx?caname=" encodeURI(encodeURI(newText)) "&caid= " caid "&t=" new Date().getTime();
$.get(url, function(data) {
if (data == "false") {
$("#test ").text("Category modification failed, please check whether the category name is duplicated!");
input_blur.trigger("focus").trigger("select"); // Select all text boxes
} else {
$("#test").text("");
objTD.html(newText);
}
});
} else {
// before and after The text is the same, turn the text box into a label
objTD.html(newText);
}
});
// Press a keyboard key in the text box
input.keydown( function(event) {
var jianzhi = event.keyCode;
var input_keydown = $(this);
switch (jianzhi) {
case 13: // Press the Enter key to change The resulting value is submitted to the database
// $("#test").text("The key value you pressed is: " jianzhi);
var newText = input_keydown.val(); // After modification The name of Serial number)
var caid = $.trim(objTD.prev().text());
// AJAX asynchronously changes the database
var url = "../handler/ChangeCaName.ashx?caname= " encodeURI(encodeURI(newText)) "&caid=" caid "&t=" new Date().getTime();
$.get(url, function(data) {
if (data == "false ") {
$("#test").text("Category modification failed, please check whether the category name is duplicated!");
input_keydown.trigger("focus").trigger("select"); // Select all text boxes
} else {
$("#test").text("");
objTD.html(newText);
}
});
} else {
// Make the text before and after the same, turn the text box into a label
objTD.html(newText);
}
break;
case 27: // Press Esc key to cancel the modification and change the text box into a label
$("#test").text("");
objTD.html(oldText);
break;
}
});
});
});

// Shield Enter key
$(document).keydown(function(event) {
switch (event.keyCode) {
case 13: return false;
}
});



Here is the general handler code ChangeCaName.ashx


using System;
using System.Web;
using BLL;
using Model;
public class ChangeCaName : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string caid = context.Request.QueryString["caid"];
string caname = context.Server.UrlDecode(context.Request. QueryString["caname"]);
// Determine whether the category with the same name already exists in the database
if (new CategoryManager().IsExists(caname))
{
context.Response.Write(" false");
return;
}
// Change database category name
Category ca = new Category(caid, caname);
bool b = new CategoryManager().Update(ca );
if (b)
{
context.Response.Write("true");
}
else
{
context.Response.Write("false ");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
表格有一条虚线外打印不到怎么办表格有一条虚线外打印不到怎么办Mar 28, 2023 am 11:38 AM

表格有一条虚线外打印不到的解决办法:1、打开excel文件,在打开的页面中点击“打印”;2、在预览页找到“无缩放”,选择调整为一页;3、选择打印机打印文档即可。

css怎么去掉表格重复的边框css怎么去掉表格重复的边框Sep 29, 2021 pm 06:05 PM

在css中,可以使用border-collapse属性来去掉表格中重复的边框,该属性可以设置表格边框是折叠为单一边框还是分开的,只需要将值设置为collapse即可把重叠的边框合并在一起,成为一个边框,实现单线边框的效果。

如何使用 Vue 实现可编辑的数据表格?如何使用 Vue 实现可编辑的数据表格?Jun 25, 2023 pm 06:20 PM

随着前端技术的不断发展,数据表格成为企业管理及数据展示的重要工具之一。在日常开发中,有时需要在数据表格中进行数据修改或新增操作,这时候就需要实现可编辑的数据表格。本文将介绍如何使用Vue实现可编辑的数据表格。一、实现思路在实现可编辑的数据表格功能时,我们需要考虑以下几点:数据呈现:将数据渲染到表格中,以便展示和编辑。表格编辑:在表格中对数据进行编辑操作。

使用JavaScript实现表格筛选功能使用JavaScript实现表格筛选功能Aug 10, 2023 pm 09:51 PM

使用JavaScript实现表格筛选功能随着互联网技术的不断发展,表格成为了网页中常见的展示数据的方式。然而,当数据量庞大时,用户往往会面临找到特定数据的困难。因此,为表格添加筛选功能,让用户可以快速找到所需的数据,成为了很多网页设计的需求。本文将介绍如何使用JavaScript实现表格筛选功能。首先,我们需要有一份表格数据。下面是一个简单的例子:<t

Vue文档中的表格勾选和全选函数操作方法Vue文档中的表格勾选和全选函数操作方法Jun 20, 2023 pm 10:33 PM

Vue是一种流行的JavaScript框架,它可以让开发人员轻松地构建交互式、响应式的Web界面。Vue框架提供了一系列的组件和指令,用于构建常见的页面元素,如表格、表单、菜单等。在这篇文章中,我们将探讨Vue文档中的表格勾选和全选函数操作方法。在Vue中,我们可以使用v-model指令将表单元素与Vue实例中的数据进行双向绑定。这使得我们可以轻松地收集用户

React中使用表格:第一部分React中使用表格:第一部分Sep 04, 2023 pm 07:21 PM

用于呈现数据的最常见的用户界面元素之一是表格。事实证明,使用表格时需要控制很多方面,例如:定义列和标题各种单元格格式(文本、数字、复选框)调整大小过滤动态成长样式在这个由两部分组成的系列中,您将了解使用ReactBootstrapTable组件在React中处理表格数据的细节。您将能够轻松创建复杂且具有专业外观的表格,并且能够自定义各个方面。开始使用 首先,您应该熟悉React本身。如果您需要React入门知识,EnvatoTuts+有一个很棒的系列可以帮助您开始使用React。在本教程中,我们

使用JavaScript实现表格数据的分页显示使用JavaScript实现表格数据的分页显示Jun 16, 2023 am 10:00 AM

随着数据的不断增长,表格显示变得更加困难。大多数情况下,表格中的数据量过大,导致表格在加载时变得缓慢,而且用户需要不断地浏览页面才能找到自己想要的数据。本文将介绍如何使用JavaScript实现表格数据的分页显示,让用户更容易找到自己想要的数据。一、动态创建表格为了使分页功能更加可控,需要动态创建表格。在HTML页面中,添加一个类似于下面的table元素。

wps表格如何按成绩高低排序wps表格如何按成绩高低排序Jun 21, 2023 am 09:30 AM

wps表格按成绩高低排序的方法:1、打开wps表格,点击菜单栏中的“开始”按钮;2、点击工具栏中的“排序”选项;3、在下拉菜单中点击“降序”选项;4、在“给出排序依据”下点击“扩展选定区域”,然后点击“排序”按钮即可按成绩高低排序。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!