我有3個文本框在html「名稱,電子郵件,評論」,我想打印在控制檯作爲對象使用jquery,但它不工作。在控制檯中打印表單數據作爲對象使用jquery
Object {name: "Ali", email: "[email protected]", message: "hi there"}
<form action="jq_ajax_contact.php" class="ajax" method="post">
<div><input type="text" name="name" placeholder="Your name"></div>
<div><input type="text" name="email" placeholder="Your email"></div>
<div><textarea name="message" placeholder="Your messsage"></textarea></div>
<div><input type="submit" value="send"></div>
</form>
$( 'form.ajax')。在( '提交',函數(){VAR 即= $(本), URL = that.attr( '行動') , method = that.attr(method), data = {}; $(this).find('[name]')。each(function(index,value){var} = $(this), name = that.attr('name'), value = that .val(); data [name] = value; }); console.log(data); 返回false; }); – mohsin