Home Web Front-end JS Tutorial jQuery realizes the method of double-clicking a Table cell to turn it into a text box and updating it to the database after inputting the content_jquery

jQuery realizes the method of double-clicking a Table cell to turn it into a text box and updating it to the database after inputting the content_jquery

May 16, 2016 pm 03:29 PM
jquery text box Mouse double click

The example in this article describes the jQuery method of double-clicking a Table cell to turn it into a text box and updating it to the database after inputting the content. Share it with everyone for your reference, the details are as follows:

JS mouse double-click event onDblClick

1

2

<td width="10%" title="双击修改" ondblclick="ShowElement(this,<%#Eval("id") %>

</td>

Copy after login

The value I bind here is the ID number corresponding to the current row passed in

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

function ShowElement(element, productid, flag, ishotorcommend) {

  if (flag == 0 && ishotorcommend == 0) {

    alert("请先设置该产品为推荐");

    return;

  }

  if (flag == 1 && ishotorcommend == 0) {

    alert("请先设置该产品为热销");

    return;

  }

  var oldhtml = element.innerHTML;//原单元格里的值

  var str = "<input type='text' name='test' style='width:50%;'";

  str += "onkeypress='return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46'";

  str += "onpaste='return !clipboardData.getData('text').match(/\D/)'";

  str += "ondragenter='return false' />";

  var newobj = document.createElement(str);  //创建新的input元素

  newobj.setAttribute("value", oldhtml);//把原来单元格中的值赋给文本框

  newobj.onblur = function() {

    element.innerHTML = this.value ? this.value : oldhtml; //当触发时判断新增元素值是否为空,为空则不修改,并返回原有值

    var sort = element.innerHTML;

    $.get("UpdateFlag.ashx?sort=" + sort + "&&productid=" + productid + "&&flag=" + flag, function(data) { });

  }

  element.innerHTML = '';

  element.appendChild(newobj);//把新的值赋到单元格

  newobj.focus();

}

Copy after login

I hope this article will be helpful to everyone in jQuery programming.

Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Use jQuery to modify the text content of all a tags

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

Understand the role and application scenarios of eq in jQuery

Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

Summary of commonly used file operation functions in PHP

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute?

See all articles