我希望在PHP或JS中这样做。类似地,如果img有特定的类,则会将查询字符串追加到其源url。让我们假设,特定的类是'hello‘&查询字符串是'?source=fb’所以,如果img有类'hello‘-
<img class="hello" src="http://example.com/1.jpg?source=fb">PHP应该检查并将其附加到img。
有什么函数能做到这一点吗?
发布于 2016-09-30 08:56:13
$('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">
像这样使用
发布于 2016-09-30 08:55:25
您可以通过提供一个函数来修改当前属性值,从而使用attr()方法来实现这一点。试试这个:
$('.hello').attr('src', function(i, src) {
return src + '?source=fb';
});发布于 2016-09-30 09:16:50
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');
}
https://stackoverflow.com/questions/39787461
复制相似问题