0
我有一個表單,並有3個文本框提交按鈕。在按鈕上文本框1應該驗證,並且n提交按鈕B,其他2應該驗證。我使用了提交處理程序並使用ajax提交表單。用兩個提交按鈕驗證表單使用Jquery
我的問題是,如果我點擊A然後它沒有調用B的提交處理程序如果B被點擊。無論首先點擊什麼,那麼另一種方法不起作用。
請幫忙!
我的代碼看起來像下面:
function set_new_rate(oid) {
alert("set_new_rate");
$("#TestForm").validate({
event: "custom",
rules: {
client_new_rate: {
required: true,
number: true
},
agent_new_rate: {
required: true,
number: true
}
},
messages: {
client_new_rate: {
required: "Required",
number: "Invalid Rate"
},
agent_new_rate: {
required: "Required",
number: "Invalid Rate"
}
},
submitHandler: function() {
var client_new_rate = $('#client_new_rate').val();
var agent_new_rate = $('#agent_new_rate').val();
var answer = confirm("Set New Rate for this Order?")
if (answer)
{
$.post('http://localhost/fc/index.php/disp/set_new_rate/',{order_id:oid,client_new_rate:client_new_rate,agent_new_rate:agent_new_rate},function(data){
if(data==1)
{
$('#rateupdated').html('<div id="display_message" class="msg msg-ok" style="margin:0 0 5px 0px;width:180px;"><p>Rate Updated Successfully!</p></div>');
$("#rateupdated").fadeIn(0).fadeOut(5000);
$('#rec_ord_cnt_prc'+oid).html(client_new_rate);
$('#client_old_rate').html(client_new_rate);
$('#agent_old_rate').html(agent_new_rate);
$('#client_new_rate').val('');
$('#agent_new_rate').val('');
}
});
}
}
});
}
function add_note(oid)
{
alert("add_note");
$("#TestForm").validate({
event: "custom",
rules: {
note_description: {
required: true
}
},
messages: {
note_description: {
required: "Required"
}
},
submitHandler: function() {
alert("add_note _ sh");
var note_description = $('#note_description').val();
var note_type = $('input:radio[name=note_type]:checked').val();
var answer = confirm("Add this "+note_type+" Note?")
if (answer)
{
$.post('http://localhost/fc/index.php/disp/add_note/',{order_id:oid,note_description:note_description,note_type:note_type},function(data){
if(data==1)
{
$('#noteadded').html('<div id="display_message" class="msg msg-ok" style="margin:5px 5px 5px 0px;width:282px;"><p>Note Added Successfully!</p></div>');
$('#note_description').val('');
$("#noteadded").fadeIn(0).fadeOut(5000);
}
});
}
}
});
}
我使用jQuery驗證插件。
我不知道爲什麼要驗證這種方式,我覺得如果你有單獨的表單,因爲他們做了不同的事情,這樣會更容易 – 2011-04-26 15:24:22