在另一个函数之后使用js函数 [英] Use a js function after another function
本文介绍了在另一个函数之后使用js函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div class="panel" id="home">
<video id='video1' width='630' autoplay controls>
<source id="source1" src="1_uno.mp4" type="video/mp4">
</video>
</div>
我拥有这个js函数,在"video1"的和处刷新了div主页,并放置了3个按钮
I' ve this js function that at the and of 'video1' makes the refresh of div home putting 3 buttons
var myVideo = document.getElementById("video1");
myVideo.addEventListener('ended',myHandler,false);
function myHandler(e) {
document.getElementById('home').innerHTML = '<button type="button" style="height: 180px; width: 200px" onclick="refreshdiv("a")"> a </button><button type="button" style="height: 180px; width: 200px" onclick="refreshdiv("b")"> b </button><button type="button" style="height: 170px; width: 200px" onclick="refreshdiv("c")"> c </button>';
}
在这部分之前一切正常,现在您可以看到onclick事件,我做了refreshdiv函数:
Until this part everything works good, now as u can see onclick event i do refreshdiv function:
function refreshdiv(str) {
if(str=='a'){
src='1_uno.mp4';
}
if(str=='b'){
src='2_due.mp4';
}
if(str=='c'){
src='3_tre.mp4';
}
document.getElementById('home').innerHTML = '<video id="video1" width="630" autoplay controls><source id="source1" src="'+ src +'" type="video/mp4"></video>';
}
问题是,当我单击按钮时,发生任何事情,并且在Chrome中出现此错误:Unexpected token }
The problem is when I click on the buttons anything happens and in Chrome i got this error: Unexpected token }
所有功能都在内部:<script></script>
推荐答案
您应该更改
onclick="refreshdiv("a")">
到onclick="refreshdiv(\'a\')">
等
'<button type="button" style="height: 180px; width: 200px" onclick="refreshdiv(\'a\')"> a </button><button type="button" style="height: 180px; width: 200px" onclick="refreshdiv(\'b\')"> b </button><button type="button" style="height: 170px; width: 200px" onclick="refreshdiv(\'c\')"> c </button>';
这是令人不安的例子 http://jsfiddle.net/8RjW5/1/
Here's wroking example http://jsfiddle.net/8RjW5/1/
这篇关于在另一个函数之后使用js函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文