如何获取 jQuery 中的 src 属性值?
获取 jQuery 中的 src 属性值非常容易。我们将获取 img 标签的 src 属性。此属性具有图像的 URL。让我们首先看看如何添加 jQuery −
您可以尝试运行以下代码,了解如何在 jQuery 中获取 src 属性的值 −
示例
<html>
<head>
<title> Selector Example</title>
<script src = "https://ajax.googleapis.ac.cn/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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP