将属性值的一部分克隆到另一个元素中的另一个属性 - js
Clone a part of an attributes value to another attribute in another element - js
我要[标题]
这是我的肆意代码:
<script>
$(document).ready(function(){
var thmbElt = document.getElementsByClassName("imgbox")[0]{var vl1 = $(this).attr("src");};
$(.h_iframe-aparat_embed_frame).attr("src",function{
return "https://www.example.com/video/video/embed/videohash/"+vl1.substr(51, 56)+"/vt/frame";
});
</script>
结果是:无
如果我没理解错的话,你想获取一个元素的src,然后在另一个元素中使用它的一部分。以下是示例:
<img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?h=350&auto=compress&cs=tinysrgb"
class="imgbox" width="80px" height="80px" />
<img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?h=350&auto=compress&cs=tinysrgb"
class="imgbox" width="80px" height="80px" />
<script>
$(document).ready(function(){
var thmbElt = document.getElementsByClassName("imgbox")[0];
var thmbElt1 = document.getElementsByClassName("imgbox")[1]; //Change this line to get img src from another field
var attr = thmbElt1.getAttribute("src");
var attrSubset = "https://www.example.com/video/video/embed/videohash/" + attr.substr(8,6) + "/vt/frame";
thmbElt.setAttribute("src", attrSubset);
});
</script>
我要[标题] 这是我的肆意代码:
<script>
$(document).ready(function(){
var thmbElt = document.getElementsByClassName("imgbox")[0]{var vl1 = $(this).attr("src");};
$(.h_iframe-aparat_embed_frame).attr("src",function{
return "https://www.example.com/video/video/embed/videohash/"+vl1.substr(51, 56)+"/vt/frame";
});
</script>
结果是:无
如果我没理解错的话,你想获取一个元素的src,然后在另一个元素中使用它的一部分。以下是示例:
<img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?h=350&auto=compress&cs=tinysrgb"
class="imgbox" width="80px" height="80px" />
<img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?h=350&auto=compress&cs=tinysrgb"
class="imgbox" width="80px" height="80px" />
<script>
$(document).ready(function(){
var thmbElt = document.getElementsByClassName("imgbox")[0];
var thmbElt1 = document.getElementsByClassName("imgbox")[1]; //Change this line to get img src from another field
var attr = thmbElt1.getAttribute("src");
var attrSubset = "https://www.example.com/video/video/embed/videohash/" + attr.substr(8,6) + "/vt/frame";
thmbElt.setAttribute("src", attrSubset);
});
</script>