如果图像源(img src)具有特定的类或ID,请将查询字符串添加到该图像源
Add query string to Image Source(img src) if it has a particular class or ID
我想在PHP或JS中使用它。类似的是,如果img有特定的类,那么一个查询字符串将附加到它的源url。让我们假设,特定的类是"hello"&查询字符串是'?source=fb'所以,如果img有类"hello"-
<img class="hello" src="http://example.com/1.jpg?source=fb">
PHP应该检查&将其附加到img src中。
有什么函数可以做到这一点?
$('img.hello').attr('src',$('img.hello').attr('src')+"addedstring")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img class="hello" src="http://example.com/1.jpg?source=fb">
像这样使用
您可以使用attr()
方法来实现这一点,方法是提供一个修改当前属性值的函数。试试这个:
$('.hello').attr('src', function(i, src) {
return src + '?source=fb';
});
You can try this by Jquery. Just give another class to your image tag, assume the class
given is "abc", it should be like :
<img class="abc hello" src="http://example.com/1.jpg">
<script>
var image_src = $('.abc').attr('src');
if($('.abc').hasClass('hello')){
$('.abc').append(image_src+'?source=fb');
}
相关文章:
- 获取图像ID并更改图像JavaScript
- 画布中的图像id
- 如何在jquery中使用图像ID获取图像位置
- 如何在点击该图像时在 canavs html5 中获取图像 ID
- 如何将图像 ID 传递给 JavaScript 页面
- 如何获取图像id
- 附加图像Id
- 通过jquery将图像id传递给php-mysql查询
- html图像id和画布
- 图像id未显示
- 当用户单击图像时传递图像名称或图像id属性
- 滑块图像id
- 单击时获取图像 ID 并将其设置为变量
- Konva从点击事件中获取图像ID
- 在dropzone .js的预览模板中为每个图像添加图像id
- 使用图像id保存图像为png, jpg和pdf
- 我需要从脚本中删除rel属性平均值,而不是图像id或任何值
- 将图像ID传递给函数
- 从touchstart事件javascript获取图像ID
- 无法引用图像id javascript