Your location:Tech News>News>Script>15 commonly used method jquery, share tips

Latest News

15 commonly used method jquery, share tips

Author:fsadmin

Views:

  $ ( "Td").dblclick (function () {

  var tdIns = $ (this);

  var tdpar = $ (this).parents ( "tr");

  tdpar.css ( "background-color", "yellow");

  if (tdIns.children ( "input").length> 0) {return false;}

  var inputIns = $ ( ""); // needs to be inserted in the code input box

  var text = $ (this).html ();

  inputIns.width (tdIns.width ()); // set input and a uniform width td

  inputIns.val (tdIns.html ()); // the copy original cell td contents input to the text box in the inserted

  tdIns.html ( ""); // delete the contents of the original cell td

  inputIns.appendTo (tdIns).focus ().select (); // need to insert the code into the input box node dom

  inputIns.click (function () {return false;});

  inputIns.keyup (function (event) {

  //1.To determine whether you press Return

  // outcome different browsers get time difference

  var myEvent = event || window.event;

  var key = myEvent.keyCode;

  if (key == 13) {

  var inputNode = $ (this);

  //1.Save the contents of the current text box

  var inputText = inputNode.val ();

  //2.Empty the contents inside td

  inputNode.parent ().html (inputText);

  }

  });

  // Process Enter and Esc events

  inputIns.blur (function () {

  var inputText = $ (this).val ();

  tdIns.html (inputText);

  tdpar.css ( "background-color", "white");

  tdIns.html (text);

  });

  });

Recommend article

Relate article