Introduction to the use of push and join methods in js

  • 2020-03-26 21:22:17
  • OfStack

 
<script type="text/javascript"> 
function delWork(id){ 
var boxes = document.getElementsByName("commonPage.idBox"); 
var selected = new Array(); 
for (var i=0; i<boxes.length; i++) { 
if(boxes[i].checked){ 
//Push () adds an element to the end of the array
selected.push(boxes[i].value); 
} 
} 
//The join() method converts all the elements in the array to strings and then concatenates them, which is exactly the opposite of the split() method of strings. Join () defaults to using ", "as the delimiter, but you can also specify the delimiter in the method
var idStr = selected.join(); 
if(idStr == ''){ 
alert(' No shift yet! '); 
return false; 
} 

if(confirm(' Be sure to delete the selected record ?')){ 

var url = '${webRoot}/base/marquee/work-delete.action?commonPage.idBox='+idStr; 
var myAjax = new Ajax.Request(url, {method:"post", onComplete:callback, asynchronous:true}); 

} 
} 

function callback(response){ 
alert(response.responseText); 
//var url = "${webRoot}/base/marquee/work-queryWorks.action"; 
var url = "${webRoot}/base/marquee/workQuery.action"; 
window.location.href = url; 

window.parent.document.getElementById("info").src = ""; 
} 

</script> 

Related articles: