jquery提交表单_jQuery提交表单

jquery提交表单

jQuery submit() function triggers when a user tries to submit a form. jQuery submit form method attaches a handler, which executes when the submit event is fired.

当用户尝试提交表单时,jQuery Submit()函数将触发。 jQuery提交表单方法附加了一个处理程序,该处理程序在触发Submit事件时执行。

jQuery提交表单 (jQuery submit form)

The syntax for submit form using jQuery submit() function:

使用jQuery Submit()函数提交表单的语法:

  • submit()

    提交()

This signature is used without any arguments. This method is a shortcut for .trigger( "submit" ).

该签名不带任何参数。 此方法是.trigger( "submit" )的快捷方式。

  • submit(handler)

    提交(处理程序)

The handler is a function, which is executed when the form is submitted. This method is a shortcut for .on( "submit", handler ).

handler是一个函数,在提交表单时执行。 此方法是.on( "submit", handler )的快捷方式。

jQuery提交表单示例 (jQuery submit form example)

Following example demonstrates submit() function usage for form submission using jQuery.

以下示例演示了使用jQuery提交表单的Submit()函数用法。

<!DOCTYPE html>
<html>
<head>
<title>jQuery Submit</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<style>
p {
margin: 0;
color: blue;
}
div,p {
margin-left: 10px;
}
.spanSuccess {
color: green;
}
</style>
</head>
<body>

<form action="javascript:alert( 'success!' );">
<div>
Name : <input type="text" name="Name" value="journalDev">
<input type="submit" value="Submit">
</div>
</form>
<span class="spanSuccess"></span>
<script>
$( "form" ).submit(function( event ) {

$( "span" ).text( "Submitted Successfully..." ).show();
event.preventDefault();

});
</script>
</body>
</html>

In above jQuery form submit example, you can see that the submit() method is triggered when you click on the Submit button. A text message is displayed as “Submitted Successfully…”.

在上面的jQuery表单Submit示例中,您可以看到单击Submit按钮时触发了commit()方法。 一条文字消息显示为“ Submittedfully…”。

jQuery表单提交演示 (jQuery form submit demo)

You can try it yourself by submitting below form.

您可以提交以下表格自行尝试。

演示地址

You may have noticed event.preventDefault() in the above code. You will see an alert, if you try the above example after removing this line. We used alert() method as the default action. So the event.preventDefault() is required in the code to prevent this default action.

您可能已经在上面的代码中注意到event.preventDefault() 。 如果删除此行后再尝试上述示例,则会看到警报。 我们使用alert()方法作为默认操作。 因此,代码中需要使用event.preventDefault()来阻止此默认操作。

That’s all for a quick jQuery form submit example. You can read learn jQuery by going through jQuery Tutorial.

这就是快速jQuery表单提交示例的全部内容。 您可以阅读jQuery Tutorial来学习jQuery。

Reference: API Doc

参考: API文档

翻译自: https://www.journaldev.com/5030/jquery-submit-form

jquery提交表单

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值