如何使用 jQuery 获取第一个匹配元素的输入值?
jqueryweb developmentfront end technology
要使用 jQuery 获取第一个匹配元素的输入值,请使用 .first() 方法。
示例
您可以尝试运行以下代码,使用 jQuery 获取第一个匹配元素的输入值 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$( "li" ).first().css( "background-color", "blue" );
});
</script>
</head>
<body>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</body>
</html>

