JS Enter dynamic Add table, right-click to dynamically delete table row

Source: Internet
Author: User

<script type= "Text/javascript" language= "JavaScript" >
Block Browser Right-click
function Stop () {
return false;
}
Document.oncontextmenu = stop;
var i=3;
$ (function () {
Click on the page other location right-click menu disappears
$ (' body '). Bind (' click ', function (EV) {
$ (' #menu '). CSS (' Display ', ' none ');
$ (' #menub '). CSS (' Display ', ' none ');
});

var $inp = $ ('. CLS ');
$inp. Bind (' KeyDown ', function (e) {
var key = E.which;
if (key = = 13) {
var id = $ ("Input:focus"). attr ("id");
if (id = = "isAbroad2") {
AddTable ();
document.getElementById ("Name3"). focus ();
}
E.preventdefault ();
var nxtidx = $inp. Index (this) + 1;
$ (". Cls:eq (" + Nxtidx + ")"). focus ();
}
});

echo Child table 1 data
var b=$ ("#dcasXmsbs_2_1s"). Val ();
if (b!=null && b!= "") {
var c=b+ "";
var d=c.replace (/__/g, ' "');
var e=d+ "";
var json=eval (' (' +e+ ') ');
if (json.length<1) {

}else{
for (var s = 0; s < json.length; s++) {
if (s>2) {
AddTable ();
}
$ ("#id" +s). Val (json[s].id);
$ ("#name" +s). Val (Json[s].name);
$ ("#birthday" +s). Val (Json[s].birthday);
$ ("#nationality" +s). Val (json[s].nationality);
$ ("#education" +s). Val (json[s].education);
$ ("#duty" +s). Val (json[s].duty);
$ ("#studyDirection" +s). Val (json[s].studydirection);
$ ("#plan" +s). Val (Json[s].plan);
$ ("#isAbroad" +s). Val (json[s].isabroad);
}
i = json.length;
}
}
});
Additional details
function addtable () {
var s = i+1;
var tbody= "tbody" + i;

var id = "id" + i;
var name = "Name" + i;
var birthday = "Birthday" + i;
var nationality = "nationality" + I;
var education = "Education" + I;
var duty = "Duty" + I;
var studydirection = "Studydirection" + i;
var plan = "plan" + i;
var isabroad = "Isabroad" + i;
$ ("#table_buffer")
. Append (
"<tbody id=\" "+tbody+" \ "class= ' Pn-ltbody ' >"
+ "<td>" + "<input type=\" hidden\ "id=\" "+id+" \ "name=\" "+id+" \ "/>" + "<input type=\" text\ "id=\" "+name+" \ "Name=\" "+name+" \ "style=\" width:80px;\ "onmouseup=\" Youjian ("+s+", this) \ "/>" + "</td>"
+ "</tbody>");
i++;
$ ("#countInfo1"). Val (i);
}

function Changenextfocus (str, s,event) {
if (Event.keycode = = 13) {
if (str = = "Netline") {
AddTable ();
var SS = s + 1;
document.getElementById ("name" + ss). focus ();
} else {
Str.focus ();
}
}
}

Table 1
Right-click event
var RowIndex; Used to delete data in the background
Var rowindex2;//identifies when forward
function Youjian (A, b) {

var container = document.getElementById (' Table_buffer ');
var menu = document.getElementById (' menu ');
if (Event.button = = 2) {
var evt = window.event | | Arguments[0];
/* Gets the current position of the right mouse button, which defines where the menu is displayed */
Menu.style.left = container.scrollleft + evt.clientx + "px";
Menu.style.top = container.scrolltop + evt.clienty +document.body.scrolltop+ "px";
/* Settings menu Visible */
$ (' #menu '). CSS (' Display ', ' block ');
RowIndex = A;
RowIndex2 = b;
}
}

Delete Row
function Delrow () {
var r = rowIndex-1;
var delId1 = $ (' #delId1 '). Val ();
if (Delid1==null | | delId1 = = "") {
var id = $ ("#id" +r). Val ();
$ (' #delId1 '). val (id);
}else{
$ (' #delId1 '). Val (delid1+ "," +$ ("#id" +r). Val ());
}
document.getElementById (' Table_buffer '). DeleteRow (RowIndex2.parentNode.parentNode.rowIndex);
}
</script>

<body>

<div id= "Menu" class= "Menuskin" >
<span style= "cursor:pointer;" id= "Shanchu" onclick= "Delrow ()" > Delete </span>
</div>

</body>

JS Enter dynamic Add table, right-click to dynamically delete table row

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.