如果像这样使用输入框中的输入事件javascript
这是我的代码,我使用onclick但不工作,如果使用enter事件
,如何使用它<form id="msg_1" action="" method="post">
<input type="text" onclick="submit_msg("1")" name="post_msg_1">
</form>
<form id="msg_2" action="" method="post">
<input type="text" onclick="submit_msg('2')" name="post_msg_2">
</form>
<form id="msg_3" action="" method="post">
<input type="text" onclick="submit_msg("3")" name="post_msg_3">
</form>
这是我的javascript
function submit_msg(uid) {
var msg= $("#post_msg_"+uid).val();
var dataString = 'msg='+ msg;
if (msg == '') {
alert("Insertion Failed Some Fields are Blank....!!");
return false;
} else {
$.ajax({
type: "POST",
url: "http://localhost/home/sendcmnt/"+uid,
data: dataString,
cache: true,
success: function(html){
$('#msg_'+uid)[0].reset(); // To reset form fields
}
});
}
return false;
}
如何使用输入框和javascript输入?
三江源
答案 0 :(得分:0)
这种做法怎么样?
HTML
$('form').on('submit', function(e) {
var $form = $(this);
var $post_msg = $form.find('[name="post_msg"]');
var msg = $post_msg.val();
var uid = $post_msg.attr('data-uid');
var dataString = 'msg='+ msg;
if (msg === '') {
alert("Insertion Failed Some Fields are Blank....!!");
return false;
} else {
$.ajax({
type: "POST",
url: "http://localhost/home/sendcmnt/"+uid,
data: dataString,
cache: true,
success: function(html){
$form[0].reset(); // To reset form fields
}
});
}
return false;
});
和JavaScript
func