Initial commit,修正
This commit is contained in:
Executable
+177
@@ -0,0 +1,177 @@
|
||||
<script type="text/javascript" >
|
||||
/*
|
||||
* JS对象格式
|
||||
* obj={key1:name1,key2:name2,key3:name3}
|
||||
*/
|
||||
|
||||
function FmShowObject(obj){
|
||||
var fm_des = "";
|
||||
console.log('JS对象记录S');
|
||||
for(var name in obj){
|
||||
fm_des += name + ":" + obj[name] + ";";
|
||||
console.log(name);
|
||||
console.log(obj[name]);
|
||||
}
|
||||
console.log('JS对象记录E');
|
||||
return fm_des;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript" charset='utf-8'>
|
||||
/*
|
||||
* JS数组格式
|
||||
* array=[val1,val2,val3,'','','',]
|
||||
*/
|
||||
|
||||
//判断是否为数组
|
||||
function isArray(o){
|
||||
if(Object.prototype.toString.call(o)=='[object Array]'){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//判断数组包含
|
||||
function Array_indexOf(array,val) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i] == val){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//从数组中移除
|
||||
function Array_remove(array,val) {
|
||||
var index = Array_indexOf(array,val);
|
||||
if (index > -1) {
|
||||
array.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//从数组中取值
|
||||
function Array_getValue(array,val) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i] == val) {
|
||||
return array[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset='utf-8'>
|
||||
/**——利用JS方法管理客户端cookie————**/
|
||||
/*
|
||||
设置cookie
|
||||
@key 键
|
||||
@value 值
|
||||
@expired 保存时长,以毫秒为单位,默认为7天 7*24*60*60*1000
|
||||
*/
|
||||
function js_setCookie(key,value,expired){
|
||||
expired = isNaN(expired) ? 7*24*60*60*1000 : expired; //使expired必为整数值
|
||||
expired = (expired<=0) ? 7*24*60*60*1000 : expired; //使expired必为正整数值
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() + expired);
|
||||
document.cookie = key + "="+ escape (value) + ";expires=" + exp.toGMTString();
|
||||
}
|
||||
|
||||
/*
|
||||
读取cookie
|
||||
@key cookie的键值
|
||||
*/
|
||||
function js_getCookie(key){
|
||||
var arr,reg=new RegExp("(^| )"+key+"=([^;]*)(;|$)");
|
||||
if(arr=document.cookie.match(reg))
|
||||
{
|
||||
return unescape(arr[2]);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
删除cookie
|
||||
@key cookie的键值
|
||||
*/
|
||||
function js_delCookie(key){
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() - 1);
|
||||
var value=getCookie(key);
|
||||
if(value !=null)
|
||||
document.cookie= key + "="+value+";expires="+exp.toGMTString();
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset='utf-8'>
|
||||
/*
|
||||
* 格式化表单
|
||||
* 返回以表单元素及对象值构成的数组对象
|
||||
* 170425 解决单选、复选、下拉框等元素name多对一时显示不正确的BUG
|
||||
*/
|
||||
|
||||
function Form_format(formid){
|
||||
var formid = (typeof(formid)=="string" ? formid : '');
|
||||
var _index, _text, _value, _length;
|
||||
if (!formid) {
|
||||
return false;
|
||||
}
|
||||
var x = document.getElementById(formid);
|
||||
var result={};
|
||||
for (var i=0;i<x.length;i++) {
|
||||
var obj = x.elements[i];
|
||||
var key = obj.name;
|
||||
if (obj.type=='radio') {
|
||||
if(obj.checked){
|
||||
result[key] = obj.value;
|
||||
}
|
||||
}else if (obj.type=='select-one') {
|
||||
//单选下拉框取值,返回单一值
|
||||
_index = obj.selectedIndex; // 选中索引
|
||||
_text = obj.options[_index].text; // 选中文本
|
||||
_value = obj.options[_index].value; // 选中值
|
||||
result[key] = _value;
|
||||
}else if (obj.type=='select-multiple') {
|
||||
//多选下拉框取值,返回数组多值
|
||||
_value =[];
|
||||
_length = obj.options.length;
|
||||
for(var j=0;j<_length;j++){
|
||||
if(obj.options[j].selected){
|
||||
_value.push(obj.options[j].value);
|
||||
}
|
||||
}
|
||||
result[key] = _value;
|
||||
}else if (obj.type=='checkbox') {
|
||||
//取复选框的值,多选项时返回数组
|
||||
if(obj.checked){
|
||||
if(result[key]==null || !isArray(result[key])){
|
||||
result[key] = [];
|
||||
}
|
||||
result[key].push(obj.value);
|
||||
}
|
||||
}else{
|
||||
result[key] = obj.value;
|
||||
}
|
||||
//以下用于打印调试结果
|
||||
//document.write(obj.name);
|
||||
//document.write('-');
|
||||
//document.write(obj.value);
|
||||
//document.write('-');
|
||||
//document.write(obj.type);
|
||||
//document.write('-');
|
||||
//document.write(obj.id);
|
||||
//document.write('<br>');
|
||||
}
|
||||
//过滤空数组,各项的具体值为仅包含一个元素的数组时,改数组为单一值
|
||||
for(k in result){
|
||||
if(isArray(result[k])){
|
||||
if (result[k].length==0) {
|
||||
result.splice(k, 1);
|
||||
}else if (result[k].length==1) {
|
||||
result[k] = result[k][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user