jquery的serialize用起來很爽吧,可惜jquery用在移動端的話效率很低,因為專案原因需要用到此函式,所以自己寫了乙個,**有些冗餘請見諒
function nodeeach(list)
return arr;
}function in_array(search,array)
}return false;
}function getjsonobjlength(jsonobj)
return length;
}function serialize(id);//返回結果的json陣列
var type1list = new array();
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='color']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='date']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='datetime']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='datetime-local']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='email']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='hidden']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='month']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='number']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='password']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='range']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='search']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='tel']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='text']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='time']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='url']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='week']") ) );
type1list = type1list.concat( nodeeach( formdom.queryselectorall("input[type='radio']:checked") ) );
for( var i = 0 ; type1list.length > i ; i++ ) );
}var type3list = formdom.queryselectorall("input[type='checkbox']:checked");
var existcheckbox = new array();
for( var i = 0 ; type3list.length > i ; i++ );
var l = formdom.queryselectorall("input[type='checkbox'][name='"+name+"']:checked");
for( var j = 0 ; l.length > j ; j++ )
valuelist.push( cache );
}var type4list = formdom.queryselectorall("select");
for( var i = 0 ; type4list.length > i ; i++ ) );
}for( var i = 0 ; valuelist.length > i ; i++ )
var value = row.value?row.value:null;
var karr = name.split("[");//是否是陣列
var cdatas = "data";
for( var j = 0; j < karr.length; j++ )else
if( eval(cdatas+" == null") ) ;" );
}}else;" );}}
eval( cdatas + " = value;" );
}return data;
}
原生JS實現表單序列化serialize
有乙個form表單,要用ajax後台提交,原來想拼接json,但是資料多了麻煩,不靈活。用html5的formdata來初始化表單 var formdata new formdata document.getelementbyid advform 看似還可以,但發現有兩個問題,一,formdata....
純JS實現課表
如下圖所示 實現乙個課表,對應現實生活中對的課表 一門課一天內,可以對應多個節次。分兩步 1 先畫出乙個空課表 2 在正確的位置上顯示課程名稱 資料中需要包含 課程名稱 course 對應週幾 week 對應的開始節次 startsection 結束節次 endsection 如下 const da...
純js實現裁剪布局
onselectstart 事件是選中的事件 document.onselectstart function e ondragstart 事件是拖拽事件 document.ondragstart function e 當右下角的按鈕滑鼠按下時 dot.onmousedown function e 大...