内爆形式元素数组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了内爆形式元素数组相关的知识,希望对你有一定的参考价值。
I frequently pass an array of elements from an html form to php, normally a list of checkboxes for removing database records. This will loop through an array of checkbox's with the same name & build a delimited string from the checked values. After I have the values in a delimited string I normally have a hidden field which holds the string & explode it on the PHP side.
// implodeFormArray(form name : String, form element name : String, delimiter : String); function implodeFormArray(f, e, del) { var form = document.forms[f]; if (typeof(form.elements[e].value) != "undefined") { if (form.elements[e].checked) return form.elements[e].value; else return ''; } else { var output = ''; var len = form.elements[e].length; for(var i=0;i<len;i++) { if (form.elements[e][i].checked) { output+= (output == '' ? '':del) + form.elements[e][i].value; } } return output; } }
以上是关于内爆形式元素数组的主要内容,如果未能解决你的问题,请参考以下文章
PHP:在除最后一个元素之外的每个元素之后显示逗号。使用“for”语句而不使用“内爆/爆炸”