2020-03-04
closest():当点击确认按钮时,需要获取表单内容,此时就需要这个函数来查找他的指定父级元素.....
$(this).closest("tr").find(".lotNo").val(str);
获取div中所有表单内容,并组成对象:
$("#btnRegister").on("click", function () {
var $this = $(this).closest("div");
var data = {};
$this.find("input").each(function () {
data[$(this).attr("name")] = $(this).val();
})
console.log(data);
//这种方法太土
//data.loginid = $this.find("#regLoginId").val()
//data.companyname = $this.find("#regCompanyName").val()
//data.password = $this.find("#regPassword").val()
//data.password2 = $this.find("#regPassword2").val()
})