js提交表单:
<a href=”javascript: document.myform.submit();”>Submit Me</a>
获取表单全部数据:
$("form").serialize()
AJAX模板:
// 抛送请求 url ="/index/user/update_sign"; postData = {'sign':sign}; $.post(url,postData,function(result){ if (result.status == 1) { $(".press_list").html(""); $.each(result.data, function (index, item) { var html = "<div class='row press_item'><div class='col-12 col-md-3 press_time'>" + item.time + "</div><div class='col-12 col-md-9'><a class='title' href='{:url('index/index/article',array('id'=>1))}'>" + item.title + "</a><div class='text'>" + item.description + "</div></div></div>"; $(".press_list").append(html); }); } }, 'json');
检测手机号:
if(!(/^1[34578]\d{9}$/.test(mobile))){ alert('请填写正确的电话号码哦!'); }
检测邮箱:
if (email_address == "" || email_address.indexOf("@") == -1 || email_address.length < 5) { alert('Invalid email address'); return false; } Email is required
刷新当前页面:
location.reload();
跳转到某页面:
window.location.href='/mobile/user/address_list';
返回上一个页面:
<a href='javascript:window.history.go(-1);'>Back ></a>
修改表单required提示文字:
<input required type="text" oninvalid="setCustomValidity('请填写必填项!');" oninput="setCustomValidity('');">
去除空格:
username=username.trim();
输入框文字转大写:
style="text-transform:uppercase"
输入框只允许输入汉字:
if(!/^[\u4e00-\u9fa5]+$/gi.test(company)){ alert("请正确填写公司名称!"); return false; }
多选框,获取选中的值:
$(".press_form .form-check").each(function (k, v) { if ($(v).children(".form-check-input").is(':checked')) { cateid.push($(v).children(".form-check-input").val()); } });
下拉框,循环设置某个选中:
$("#stock_edit .room option").each(function () { if ($(this).val() == result.data.room) { $(this).attr("selected", true); } });
推荐阅读: