表單元素獲取以及提交
阿新 • • 發佈:2018-11-10
//獲取單選框值
var rfileaccess = $("input[name='rfileaccess']:checked").val();
console.log(rfileaccess+"--"+cggaccess);
//獲取複選框的值
var data = "";
$("input[name='dataaccess']:checked").each(function(){data += $(this).val()+",";
})
console.log(data);
//獲取表單所有的值
var refInfo = {};
//定義一個不能為空欄位陣列
//var notnull = ["sitename","ip","ftpusername","ftppassword","longitude","latitude","ellipsoidheight","rfilepath"];var fieldL=$("#addsite").find(" [name]");
var index = $.inArray(fieldL[i1].name,notnull);
if(index >= 0 && fieldL[i1].value.trim()==""){
fieldL[i1].focus();
return;
}
refInfo[fieldL[i1].name]=fieldL[i1].value;
}
console.log(refInfo);
//向後臺提交
$.ajax({
url: "${pageContext.request.contextPath}/site/insertsite.com",
data: {dataMap:JSON.stringify(refInfo)},
success: function(rt){
if(rt=="no"){
layer.msg('儲存失敗', {
time: 2000, //2s後自動關閉
/* btn: ['明白了', '知道了', '哦'] */
});
}
if(rt=="yes"){
layer.msg('儲存成功', {
time: 2000, //1s後自動關閉
});
}
}
});