這段時(shí)間,經(jīng)常用javascript獲取各種form中的提交數(shù)據(jù)??紤]到代碼的一致和邏輯的簡化,建立如下兩個(gè)js函數(shù)用統(tǒng)一的方式獲取form中的數(shù)據(jù).根據(jù)Formid 和 Inputid 獲得數(shù)據(jù)
公司主營業(yè)務(wù):成都做網(wǎng)站、成都網(wǎng)站制作、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出杏花嶺免費(fèi)做網(wǎng)站回饋大家。
函數(shù)調(diào)用方式如下德例子.
獲得數(shù)據(jù):
var CharString=getValue(formid,'CharString');
var TestCondition=getValue(formid,'TestCondition');
var Hvalue=getValue(formid,'Hvalue');
var Lvalue=getValue(formid,'Lvalue');
var HunitID=getValue(formid,'HunitID');
var LogicTerm=getValue(formid,'LogicTerm');
設(shè)置數(shù)據(jù)
if(CharString) setValue(formid,'CharString',CharString);
Form的形式如下:
測試條件
-->
低值數(shù)據(jù)
操作符號(hào)
如上,所有不同類型的input的取值和設(shè)值都是一致的。注意,每個(gè)Input都必須有id屬性,form也是
兩個(gè)支持js函數(shù)如下:
//忽略類型,對Form中的Input數(shù)據(jù)設(shè)置值
function setValue(formid,inputid,strvalue) {
var l = new Number();
if (!strvalue) return ;
if (strvalue=='') return ;
eval('l = document.' + formid + '.elements.length')
for (var i = 0; i < l; i++) {
var tempid = new String();
var temptype = new String();
eval('tempid= document.' + formid + '.elements[i].name;');
eval('temptype= document.' + formid + '.elements[i].type;');
if (tempid==inputid){
if (temptype=='text'){
eval('document.' + formid + '.elements[i].value=strvalue;');
}else if (temptype=='textarea'){
eval('document.' + formid + '.elements[i].value=strvalue;');
}else if (temptype=='hidden'){
eval('document.' + formid + '.elements[i].value=strvalue;');
}else if(temptype=='select-one'){
var optionLen=new Number();
eval('optionLen=(document.' + formid + '.elements[i].options.length)');
for(var j=0;j
}
}else if(temptype=='radio'){
eval('if (document.' + formid + '.elements[i].value==strvalue) document.' + formid + '.elements[i].checked=true;');
}else if(temptype=='checkbox'){
var strvalues=(','+strvalue+',').split(',');
for(var j=0;j
eval('if (document.' + formid + '.elements[i].value==strvalues[j] ) document.' + formid + '.elements[i].checked=true; ');
}
}
}else if (temptype=='select-multiple'){
var strvalues=(','+strvalue+',').split(',');
var optionLen=new Number();
eval('optionLen=(document.' + formid + '.elements[i].options.length)');
for(var k=0;k
}
}
}
}
}
}
//忽略類型,對Form中的Input數(shù)據(jù)取值
function getValue(formid,inputid) {
var tempvalue = new String();
var l = new Number();
eval('l = document.' + formid + '.elements.length')
for (var i = 0; i < l; i++) {
var tempid = new String();
var temptype = new String();
eval('tempid= document.' + formid + '.elements[i].name;');
eval('temptype= document.' + formid + '.elements[i].type;');
//alert(tempid);
//alert(temptype);
if (tempid==inputid){
if (temptype=='text'){
eval('tempvalue= document.' + formid + '.elements[i].value;');
}else if (temptype=='textarea'){
eval('tempvalue= document.' + formid + '.elements[i].value;');
}else if (temptype=='hidden'){
eval('tempvalue= document.' + formid + '.elements[i].value;');
}else if(temptype=='select-one'){
eval('tempvalue=document.' + formid + '.elements[i].options[document.' + formid + '.elements[i].selectedIndex].value;');
}else if(temptype=='radio'){
eval('if(document.' + formid + '.elements[i].checked) tempvalue=document.' + formid + '.elements[i].value;');
}else if(temptype=='checkbox'){
var checkValue=new String();
checkValue="";
eval('if (document.' + formid + '.elements[i].checked==true) {checkValue=document.' + formid + '.elements[i].value}');
if(checkValue==''){
}else{
if (tempvalue==''){
tempvalue+=checkValue;
}else{
tempvalue+=','+checkValue;
}
}
}else if (temptype=='select-multiple'){
//計(jì)算Option的個(gè)數(shù)
//根據(jù)個(gè)數(shù)循環(huán)檢測數(shù)值,并
var optionLen=new Number();
eval('optionLen=(document.' + formid + '.elements[i].options.length)');
for(var j=0;j
checkValue="";
eval('if (document.' + formid + '.elements[i].options[j].selected) checkValue=(document.' + formid + '.elements[i].options[j].value);');
if(checkValue==''){
}else{
if (tempvalue==''){
tempvalue+=checkValue;
}else{
tempvalue+=','+checkValue;
}
}
}
//循環(huán)檢查數(shù)據(jù)
}
}
}
return tempvalue;
}
標(biāo)題名稱:(ZT)寫兩個(gè)通用函數(shù)統(tǒng)一javascript獲取form數(shù)據(jù)的方式
標(biāo)題來源:http://www.ekvhdxd.cn/article10/jsjdgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站內(nèi)鏈、小程序開發(fā)、靜態(tài)網(wǎng)站、網(wǎng)站維護(hù)、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)