如何使用每个函数或其他函数编写我在 jquery 中选择的每个表单提交(无需逐个编写表单 jquery 提交)?我对此进行了编码,但不起作用。
$("form#form_report_user,form#send_pm").submit(function(){
$.post($(this).attr('action'), $(this).serialize(), function(data) {
$($(this).parent()).html("<img src='../images/loader.gif' alt='loading...' />");
switch (parseInt(data.succ_code)){
case 1: $($(this).parent()).html(data.html);break;
default: $($(this).parent()).html(data.html);
}
}, 'json');
return false;
});
和 html :
<div class="send_pm">
<h1>....</h1>
<form action="load/send_pm.php" method="post" id="send_pm">
<input name="user_id" type="hidden" value="<?php echo $userid; ?>" />
<div class="cleaner"></div>
<span style="font-size:12px;">Subject : </span><br />
<input name="subject" type="text" style="margin-top: 10px; margin-bottom: 10px;" />
<div class="cleaner"></div>
<span style="font-size:12px;">Message : </span>
<div class="cleaner"></div>
<textarea name="msg" id="add_txtarea" style="margin-top: 10px; margin-bottom: 10px;width: 220px;height: 100px;"></textarea>
<div class="cleaner"></div>
<input type="submit" value="send" name="send" class="nice_button" />
</form>
</div>
<div class="gold_transfer">
<h1>...</h1>
<span style="font-size:12px;">....</span><br>
<form action="load/transfer_gold.php" method="post" id="transfer_gold">
<input name="user_id_receive" type="hidden" value="<?php echo $userid; ?>" />
<div class="cleaner"></div>
<img src="../images/gold-coin.png" style="width:25px; height: 25px; padding-top:10px;" />
<input name="gold_total_transfer" id="gold_total" value="" type="text" style="margin-top: 10px; margin-bottom: 10px; width: 40px;" />
<div class="cleaner"></div>
<input type="submit" value="send" name="send" class="nice_button" />
</form>
</div>