Ι无法找到当我点击圈子一次又一次地改变attr时的情况。对于那两个attr。我显然是新手代码!谢谢大家快速回复。
<body>
<iframe width="560" height="315" src="https://www.youtube.com/embed/5SgyFaBS7WI" frameborder="0" allowfullscreen></iframe>
<div id="circle"></div>
<script type="text/javascript">
$("#circle").click(function() {
$("iframe").attr("src", <iframe width="560" height="315" src="https://www.youtube.com/embed/0WazFtJSIHk" frameborder="0" allowfullscreen></iframe>, function("src","https://www.youtube.com/embed/5SgyFaBS7WI");
});
</script>
</body>
答案 0 :(得分:0)
你做错了。
jQuery('iframe').attr('src', 'http://www.youtube.com/...');
仅添加youtube网址,而不是整个HTML代码。
答案 1 :(得分:0)
<body>
<iframe width="560" height="315" src="https://www.youtube.com/embed/5SgyFaBS7WI" frameborder="0" allowfullscreen></iframe>
<div id="circle">Click me</div>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
var links = [
"https://www.youtube.com/embed/0WazFtJSIHk",
"https://www.youtube.com/embed/5SgyFaBS7WI"
];
var counter = 0;
$("#circle").click(function() {
$("iframe").attr("src", links[counter % links.length]);
counter++;
});
});
</script>
</body>