如何在 jQuery 中获取 src 属性的值?
jqueryweb developmentfront end technology
在 jQuery 中获取 src 属性的值非常简单。我们将获取 img 标签的 src 属性。该属性包含图像的 URL。让我们先来看看如何添加 jQuery 代码。
您可以尝试运行以下代码来学习如何在 jQuery 中获取 src 属性的值。
示例
<html>
<head>
<title> Selector Example</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
alert($('#myimg').attr('src'));
});
</script>
</head>
<body>
<p>Logo</p>
<img src="/green/images/logo.png" id="myimg">
</body>
</html>

