本文介绍了在另一个函数之后使用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>';这是令人不安的例子 jsfiddle/8RjW5/1/
Here's wroking example jsfiddle/8RjW5/1/
更多推荐
在另一个函数之后使用js函数
发布评论