如何将此表单输入存储在变量中,以后我可以使用 - 而不是附加到URL的末尾?
<script type="text/javascript">
$(function() {
var tag_box = $("<div>").appendTo("body").css({
"width": "40px",
"height":"40px",
"border":"4px solid #000000",
"position":"absolute",
"display":"none",
"padding":"15px"
});
var comment_box = $("<form action='#'><input id='comment' type='text' name='comment' placeholder='Add comment'></form>").appendTo(tag_box).css({"position":"absolute"});
$("#image-wrapper").live("click", function(e) {
tag_box.css({
"left": e.pageX - 40,
"top": e.pageY - 40,
"display": "block"
})
.after(comment_box.css({
"left": e.pageX - 65,
"top": e.pageY + 40
}));
return false;
});
});
</script>
<body>
<div align="center">
<img src="images/ror1.gif" width="760" height="182" alt="Ror1" id="image-wrapper">
</div>
</body>
答案 0 :(得分:1)
通过从submit
(onsubmit)事件处理程序返回false来阻止它提交。表单数据(参数名称+值)可以通过serialize
:
$("form").live("submit", function() {
var params = $(this).serialize();
alert(params);
return false;
});