function removeComment(bID) {
$('#submitChangeComment').attr('disabled', true);
$.ajax({
type: "POST",
url: "misc/changeComment.php",
data: {
mode: 'del',
bID : bID,
comment : $('input[name=Comment]:visible').val()
},
success: function(msg){
$('#submitChangef').attr('disabled', false);
$('#currentComment' + bID).hide();
var $msg = $("#nowCurrentComment" + bID).find('.comment');
// if it already has a comment, fade it out, add the text, then fade it back in
if ($msg.text().length) {
$msg.fadeOut('fast', function() {
$msg.text(msg).fadeIn('fast');
});
} else {
// otherwise just hide it, add the text, and then fade it in
$msg.hide().text(msg).fadeIn('fast');
}
}
});
}
function FriendChangeComment(bID) {
$('#submitChangef').attr('disabled', true);
$.ajax({
type: "POST",
url: "misc/changeComment.php",
data: {
mode: 'edit',
bID : bID,
comment : $('input[name=Comment]:visible').val()
},
success: function(msg) {
$('#submitChangef').attr('disabled', false);
$('#currentComment' + bID).hide();
var $msg = $("#nowCurrentComment" + bID).find('.comment');
// if it already has a comment, fade it out, add the text, then fade it back in
if ($msg.text().length) {
$msg.fadeOut('fast', function() {
$msg.text(msg).fadeIn('fast');
});
} else {
// otherwise just hide it, add the text, and then fade it in
$msg.hide().text(msg).fadeIn('fast');
}
}
});
}
形式:
<form action="javascript:FriendChangeComment(<? echo $showInfo["bID"]; ?>)" method="post">
change comment for <br><?php echo fullname($showInfo["bID"]); ?>:<br>
<input type="text" name="Comment" value="<?=$showC["comment"];?>" size="20">
<input name="submit" type="submit" id="submitChangef" value="Save">
<input name="removeC" type="button" id="submitremoveComment" value="remove" onClick="">
</form>
我有兩個在一個表單提交按鈕。如果你點擊第一個「submitChangef」,我希望它運行FriendChangeComment(),如果你點擊「removeComment」,我希望它運行removeComment。兩者都是相同的功能,它們之間的區別僅在於ajax數據中的模式:(del,edit)。我不知道如何縮短代碼並簡化代碼,因爲它們都是彼此完全重複的(幾乎)。
這怎麼辦?
id =「processBtnClick()? – Karem 2010-11-17 14:26:08
對不起,當然「onclick」,而不是「id」 – heximal 2010-11-17 15:04:10