2017-08-27 2 views
0

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> 

ザッツ結果がありません。何も

+0

vl1は定義済みですか、または未定義ですか? – Nikolaus

答えて

0

私は理解していればある要素の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> 
+0

ありがとうございますが、まだ動作していません... – F4125h4d

+0

表示されるエラーメッセージは何ですか?あなたのhtmlとコードの詳細を提供することができます。 –

+0

未知の型エラー:nullのプロパティ 'substr'を読み取れません – F4125h4d

関連する問題