在另一个函数之后使用js函数

编程入门 行业动态 更新时间:2024-10-25 04:16:28
本文介绍了在另一个函数之后使用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函数

本文发布于:2023-11-26 21:09:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635205.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!