如何将 id 名称传递给 jQuery 验证并发送给控制器?
How to pass the id name to the jQuery validation and send to the controller?
我有两个锚标记,点击时,我必须获取 id 值。
所以我尝试了下面的代码,我得到了 id。现在获得 id 后,我必须显示弹出窗口。所以弹出窗口也在显示。
<div class="buttonSet">
<a href="javascript:void(0);" id="sample1">Sample one</a>
<a href="javascript:void(0);" id="sample2">Sample two</a>
</div>
$(".buttonSet a").click(function() {
alert(this.id);//getting the id name, just for an example
$('#Popup').show();
});
弹出代码为
<div class="" id="Popup" style="display:none">
<form action="" method="post" name="form1" id="form1" autocomplete="off">
<div class="form-group ffl-wrapper">
<label for="name" class="ffl-label">Name</label>
<input type="text" name="name" class="form-control" id="name">
</div>
<div class="form-group ffl-wrapper">
<label for="email" class="ffl-label">Email</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<div class="form-group ffl-wrapper">
<label for="mobileno" class="ffl-label">Mobile Number</label>
<input type="text" name="mobileno" class="form-control" id="mobileno">
</div>
<div class="form-group text-center btn_submit_action">
<input type="submit" name="send" class="" value="Submit">
</div>
</form>
</div>
现在我很困惑如何将 id 值传递给 jQuery 验证以及提交按钮如何工作。我的意思是我有一个表格和两个按钮。单击按钮将打开相同的表单。我必须获取单击哪个按钮的信息并将该按钮 ID 传递给 jQuery 验证并发送到表单。因为我必须存储被点击的按钮的名称。
jQuery 验证
$("#form1").validate({
rules: {
name: {
required: true,
minlength: 3,
lettersonly: true
},
email: {
required: true,
email: true
},
mobileno: {
required: true,
minlength: 10,
maxlength: 10,
number: true
}
},
submitHandler: function(form) {
$.ajax({
url: "//my url",
type: "POST",
data: $('#form1').serialize(),
success: function(data) {
$("#Popup").hide();
$("#popup_success").show();
},
}); // AJAX Get Jquery statment
}
});
获取 id 后,您必须将其作为隐藏输入添加到表单中,如下所示
$(".buttonSet a").click(function() {
alert(this.id);//getting the id name, just for an example
var id=$(this.id);
$('#Popup #id').val(id);
$('#Popup').show();
});
为此,您必须向表单添加一个输入元素
<div class="" id="Popup" style="display:none">
<form action="" method="post" name="form1" id="form1" autocomplete="off">
<input type="number" name="id" class="form-control" id="id">
<div class="form-group ffl-wrapper">
<label for="name" class="ffl-label">Name</label>
<input type="text" name="name" class="form-control" id="name">
</div>
<div class="form-group ffl-wrapper">
<label for="email" class="ffl-label">Email</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<div class="form-group ffl-wrapper">
<label for="mobileno" class="ffl-label">Mobile Number</label>
<input type="text" name="mobileno" class="form-control" id="mobileno">
</div>
<div class="form-group text-center btn_submit_action">
<input type="submit" name="send" class="" value="Submit">
</div>
</form>
</div>
现在是时候在您的验证脚本中添加以下规则了
id: {
required: true
}
我有两个锚标记,点击时,我必须获取 id 值。
所以我尝试了下面的代码,我得到了 id。现在获得 id 后,我必须显示弹出窗口。所以弹出窗口也在显示。
<div class="buttonSet">
<a href="javascript:void(0);" id="sample1">Sample one</a>
<a href="javascript:void(0);" id="sample2">Sample two</a>
</div>
$(".buttonSet a").click(function() {
alert(this.id);//getting the id name, just for an example
$('#Popup').show();
});
弹出代码为
<div class="" id="Popup" style="display:none">
<form action="" method="post" name="form1" id="form1" autocomplete="off">
<div class="form-group ffl-wrapper">
<label for="name" class="ffl-label">Name</label>
<input type="text" name="name" class="form-control" id="name">
</div>
<div class="form-group ffl-wrapper">
<label for="email" class="ffl-label">Email</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<div class="form-group ffl-wrapper">
<label for="mobileno" class="ffl-label">Mobile Number</label>
<input type="text" name="mobileno" class="form-control" id="mobileno">
</div>
<div class="form-group text-center btn_submit_action">
<input type="submit" name="send" class="" value="Submit">
</div>
</form>
</div>
现在我很困惑如何将 id 值传递给 jQuery 验证以及提交按钮如何工作。我的意思是我有一个表格和两个按钮。单击按钮将打开相同的表单。我必须获取单击哪个按钮的信息并将该按钮 ID 传递给 jQuery 验证并发送到表单。因为我必须存储被点击的按钮的名称。
jQuery 验证
$("#form1").validate({
rules: {
name: {
required: true,
minlength: 3,
lettersonly: true
},
email: {
required: true,
email: true
},
mobileno: {
required: true,
minlength: 10,
maxlength: 10,
number: true
}
},
submitHandler: function(form) {
$.ajax({
url: "//my url",
type: "POST",
data: $('#form1').serialize(),
success: function(data) {
$("#Popup").hide();
$("#popup_success").show();
},
}); // AJAX Get Jquery statment
}
});
获取 id 后,您必须将其作为隐藏输入添加到表单中,如下所示
$(".buttonSet a").click(function() {
alert(this.id);//getting the id name, just for an example
var id=$(this.id);
$('#Popup #id').val(id);
$('#Popup').show();
});
为此,您必须向表单添加一个输入元素
<div class="" id="Popup" style="display:none">
<form action="" method="post" name="form1" id="form1" autocomplete="off">
<input type="number" name="id" class="form-control" id="id">
<div class="form-group ffl-wrapper">
<label for="name" class="ffl-label">Name</label>
<input type="text" name="name" class="form-control" id="name">
</div>
<div class="form-group ffl-wrapper">
<label for="email" class="ffl-label">Email</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<div class="form-group ffl-wrapper">
<label for="mobileno" class="ffl-label">Mobile Number</label>
<input type="text" name="mobileno" class="form-control" id="mobileno">
</div>
<div class="form-group text-center btn_submit_action">
<input type="submit" name="send" class="" value="Submit">
</div>
</form>
</div>
现在是时候在您的验证脚本中添加以下规则了
id: {
required: true
}