我从服务中返回了以下json:
{
"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
}
如何使用javascript获取src
属性值,即https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed
?
答案 0 :(得分:5)
从iframe
创建一个jQuery对象并获取src
属性:
var jsonString = {"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"}
var src = $(jsonString.html).attr("src");
$("#source").html(src);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="source"></div>
答案 1 :(得分:1)
var data = {
"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>"
}
console.log(data.html);
var str = data.html;
var word = str.split(" ");
var word1 = word[3].split('"');
console.log(word1[1]);
我做了几次分手,最后我https://www.youtube.com/embed/FQpUOimNvXA?feature=oembed