This article mainly introduces the js operation of table rows and columns without refreshing the new implementation. You can refer to the following code for reference only. If you force copy, modify the page id.
The Code is as follows:
// Query the database's Qualified Data
Function SelectAlterNativeVenues (field)
{
Var xmlhttp;
Var pid = document. getElementById ("nameandaddress"). value;
Var url = "$ {RetrieveURL }? AccessorType =$ {AccessorType }";
Url = url + "& method = RetrieveSelectResult & NameAndAddress =" + escape (pid );
If (window. XMLHttpRequest)
{
Xmlhttp = new XMLHttpRequest ();
}
Else if (window. ActiveXObject)
{
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP"); // IE
}
If (xmlhttp! = Null)
{
Xmlhttp. open ("GET", url, true );
Xmlhttp. setRequestHeader ("If-Modified-Since", "0 ");
Xmlhttp. send (null );
Xmlhttp. onreadystatechange = function processRefreshUsers () // Registration Method
{
If (xmlhttp. readyState = 4)
{
If (xmlhttp. status = 200)
{
// ResponseXML gets the returned value of the RetrieveCitiesByProvinceId method.
Var datas = xmlhttp.responseXML.doc umentElement. getElementsByTagName ("AlterNativeVenues ");
Var nname = document. getElementById ("table1 ");
Var pchildren = nname. childNodes; // clear rows and columns in the table
For (var a = 0; {
Nname. removeChild (pchildren [a]);
}
// Add query rows
Var parameter ow = nname. insertRow (0 );
Var aaCell = maid. insertCell (0 );
AaCell. innerHTML =" ";
AaRow. insertCell (1). innerHTML = "query ";
// Add a title line
Var aRow = nname. insertRow (1 );
ARow. insertCell (0). innerHTML = "";
ARow. insertCell (1). innerHTML = "name ";
ARow. insertCell (2). innerHTML = "Address ";
ARow. insertCell (3). innerHTML = "phone ";
// Add data rows cyclically
For (I = 0; I <datas. length; I ++)
{
Var Id = datas [I]. getElementsByTagName ("Id") [0]. firstChild. nodeValue;
Var Name = datas [I]. getElementsByTagName ("Name") [0]. firstChild. nodeValue;
Var Address = datas [I]. getElementsByTagName ("Address") [0]. firstChild. nodeValue;
Var Phone = datas [I]. getElementsByTagName ("Phone") [0]. firstChild. nodeValue;
Var aNewRow = nname. insertRow (I + 2 );
ANewRow. insertCell (0). innerHTML =" ";
ANewRow. insertCell (1). innerHTML = Name;
ANewRow. insertCell (2). innerHTML = Address;
ANewRow. insertCell (3). innerHTML = Phone;
}
}
}
}
}
}
// Add selected data
Function AddRowSelectAfter (id, field)
{
// Divide all IDs in the hidden domain and bind the corresponding checked
Var state = false; // determines whether the following list exists
Var _ hiddenId = document. getElementById (field). value. substr (0, document. getElementById (field). value. length-1). split (',');
For (j = 0; j <_ hiddenId. length; j ++)
{
If (_ hiddenId [j] = id. split ('_') [1])
{
State = true;
}
}
If (state = false)
{
// You only need to click checkbox to change the value of the hidden domain.
// The id needs to be removed from the hidden control when the status is not selected
Var arrs = document. getElementById (field). value. substr (0, document. getElementById (field). value. length-1). split (',');
// Define a field to obtain the id again
Var newids = "";
For (var arr = 0; arr {
If (arrs [arr]! = Id. split ('_') [1])
Newids + = arrs [arr] + ",";
}
// Assign a value to the hidden control again
// The last character may be,
Var fh = newids. substr (newids. length-1, newids. length );
If (fh = ",")
Document. getElementById (field). value = newids. substr (0, newids. length-1 );
Else
Document. getElementById (field). value = newids;
If (document. getElementById (id). checked = false)
{
// Click to change the selected status to non-click to remove the selected venue
Document. getElementById (id). checked = false;
// Set the id for tr to delete tr
Document. getElementById ("table2"). deleteRow (document. getElementById ("NewRow _" + id. split ('_') [1]). rowIndex );
}
Else
{
Document. getElementById (id). checked = true;
Var input = document. getElementById (field );
Var xmlhttp;
Var url = "$ {RetrieveURL }? AccessorType =$ {AccessorType }";
Url = url + "& method = SelectResult & id =" + id;
If (window. XMLHttpRequest)
{
Xmlhttp = new XMLHttpRequest ();
}
Else if (window. ActiveXObject)
{
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP"); // IE
}
If (xmlhttp! = Null)
{
Xmlhttp. open ("GET", url, true );
Xmlhttp. setRequestHeader ("If-Modified-Since", "0 ");
Xmlhttp. send (null );
Xmlhttp. onreadystatechange = function processRefreshUsers () // Registration Method
{
If (xmlhttp. readyState = 4)
{
If (xmlhttp. status = 200)
{
// ResponseXML gets the returned value of the RetrieveCitiesByProvinceId method.
Var datas = xmlhttp.responseXML.doc umentElement. getElementsByTagName ("AlterNativeVenues ");
Var nname = document. getElementById ("table2 ");
Nname. style. width = "560px ";
If (nname. rows. length = 0 & datas. length> 0)
{
// The first line
Var firstRow = nname. insertRow (0 );
FirstRow. id = "NewRow_0 ";
FirstRow. insertCell (0). innerHTML = "name ";
FirstRow. insertCell (1). innerHTML = "Address ";
FirstRow. insertCell (2). innerHTML = "phone ";
FirstRow. insertCell (3). innerHTML = "operation ";
}
For (I = 0; I <datas. length; I ++)
{
Var Id = datas [I]. getElementsByTagName ("Id") [0]. firstChild. nodeValue;
Var Name = datas [I]. getElementsByTagName ("Name") [0]. firstChild. nodeValue;
Var Address = datas [I]. getElementsByTagName ("Address") [0]. firstChild. nodeValue;
Var Phone = datas [I]. getElementsByTagName ("Phone") [0]. firstChild. nodeValue;
Var aNewRow = nname. insertRow (nname. rows. length );
ANewRow. id = "NewRow _" + Id;
Var oneCell = aNewRow. insertCell (0 );
OneCell. innerHTML = Name;
OneCell. width = 140;
Var twoCell = aNewRow. insertCell (1 );
TwoCell. innerHTML = Address;
TwoCell. width = 280;
Var threeCell = aNewRow. insertCell (2 );
ThreeCell. innerHTML = Phone;
ThreeCell. width = 100;
Var fourCell = aNewRow. insertCell (3 );
FourCell. innerHTML = "delete ";
FourCell. width = 40;
If (input. value! = "")
Input. value + = ",";
Input. value + = Id;
}
}
}
}
}
}
}
}
Function DeleteRow (id, obj, field)
{
Obj. parentNode. removeChild (obj. parentNode. parentNode)
Var nname = document. getElementById ("table2 ");
If (nname. rows. length = 1)
{
Nname. deleteRow (0 );
}
// If the list above does not exist after the query has been stored in the database
If (document. getElementById ("AlterNativeVenues _" + id )! = Null | document. getElementById ("AlterNativeVenues _" + id )! = Undefined)
{
If (document. getElementById ("AlterNativeVenues _" + id). checked = true)
{
Document. getElementById ("AlterNativeVenues _" + id). checked = false;
}
}
// The id needs to be removed from the hidden control when the status is not selected
Var arrs = document. getElementById (field). value. substr (0, document. getElementById (field). value. length-1). split (',');
// Define a field to obtain the id again
Var newids = "";
For (var arr = 0; arr {
If (arrs [arr]! = Id)
Newids + = arrs [arr] + ",";
}
// Assign a value to the hidden control again
// Assign a value to the hidden control again
// The last character may be,
Var fh = newids. substr (newids. length-1, newids. length );
If (fh = ",")
{
Document. getElementById (field). value = newids. substr (0, newids. length-1 );
}
Else
Document. getElementById (field). value = newids;
}