jQuery提交表单验证移动端还是PC端
写手在作画的夜晚,留下路人惊叹
和大家分享一下一个表单提交的小案例
![](https://img2018.cnblogs.com/blog/1775427/201909/1775427-20190924174639897-1255786435.png)
好啦,就在这里了下面赋上代码
function toSubmit() {
var source
var isMobile = /Android|webOs|iPhone|iPad|BlackBerry/i.test(navigator.userAgent)
if (isMobile) {
source = 2
} else {
source = 1
}
var name = $("#card_name").val()
var phoneNumber = $("#card_name1").val()
var investRegion = $("#card_name3").val()
console.log(source)
$.ajax({
type: "POST",
url: "/addPotentialInvestor",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
"name": name,
"phoneNumber": phoneNumber,
"investRegion": investRegion,
"source": source.toString()
}),
success: function(res) {
console.log(res)
$("#card_name").val("")
$("#card_name1").val("")
$("#card_name3").val("")
},
error: function(err) {
console.log(err, "失败")
}
})
setTimeout('$(".titleConBackground").fadeIn()', 300);
setTimeout('$(".titleConBackground").fadeOut()', 1200);
}