小码哥的IT人生

首页 > JS > jQuery

jQuery :submit 选择器 概述

jQuery 2022-06-01 12:03:29小码哥的IT人生shichen

jQuery :submit 选择器

实例

选择 type="submit" 的 <input> 和 <button> 元素:

$(":submit")

完整实例:

<html>
<head>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(":submit").css("background-color","#B2E0FF");
});
</script>
</head>
<body>
<html>
<body>
<form action="">
Name: <input type="text" name="user" />
<br />
Password: <input type="password" name="password" />
<br />
<button type="button">Useless Button</button>
<input type="button" value="Another useless button" />
<br />
<input type="reset" value="Reset" />
<input type="submit" value="Submit" />
<br />
<button type="submit">Submit Button</button>
<br />
</form>
</body>
</html>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

定义和用法

:submit 选择器选取类型为 submit 的 <button> 和 <input> 元素。

如果 <button> 元素没有定义类型,大多数浏览器会把该元素当作类型为 submit 的按钮。

语法

$(":submit")

提示和注释

提示:通过该选择器使用 input:submit 不会选择 <button> 元素。

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024