embed 元素 用javascript 控制 play stop的实现
2014-02-25 15:42
591 查看
主要代码如下:asp.net 实现方式
因为需要从数据库里抓路径,这里用到了DataBinder.Eval
<input id="btnPlay" type="button" value="播放" onclick="play('<%# DataBinder.Eval(Container.DataItem,"HttpRoot") %>');" />
<input id="btnStop" type="button" value="停止" onclick="stop123();" />
播放: function play(file) {
var embed;
// alert(file);
embed = document.getElementById('firstSound');
if (embed == null) {
embed = document.createElement("embed");
embed.setAttribute('id', 'firstSound');
embed.setAttribute('name', 'firstSound');
embed.setAttribute('controls', 'smallconsole');
// embed.setAttribute('width', 200);
// embed.setAttribute('height', 0);
embed.setAttribute('src', file);
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);
mydiv.appendChild(embed);
} else {
mydiv.removeChild(embed);
embed = document.createElement("embed");
embed.setAttribute('id', 'firstSound');
embed.setAttribute('name', 'firstSound');
embed.setAttribute('controls', 'smallconsole');
// embed.setAttribute('width', 200);
// embed.setAttribute('height', 0);
embed.setAttribute('src', file);
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);
mydiv.appendChild(embed);
}
}
停止:
function stop123() {
var sounder = document.getElementById('firstSound');
sounder.stop();
}
因为需要从数据库里抓路径,这里用到了DataBinder.Eval
<input id="btnPlay" type="button" value="播放" onclick="play('<%# DataBinder.Eval(Container.DataItem,"HttpRoot") %>');" />
<input id="btnStop" type="button" value="停止" onclick="stop123();" />
播放: function play(file) {
var embed;
// alert(file);
embed = document.getElementById('firstSound');
if (embed == null) {
embed = document.createElement("embed");
embed.setAttribute('id', 'firstSound');
embed.setAttribute('name', 'firstSound');
embed.setAttribute('controls', 'smallconsole');
// embed.setAttribute('width', 200);
// embed.setAttribute('height', 0);
embed.setAttribute('src', file);
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);
mydiv.appendChild(embed);
} else {
mydiv.removeChild(embed);
embed = document.createElement("embed");
embed.setAttribute('id', 'firstSound');
embed.setAttribute('name', 'firstSound');
embed.setAttribute('controls', 'smallconsole');
// embed.setAttribute('width', 200);
// embed.setAttribute('height', 0);
embed.setAttribute('src', file);
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);
mydiv.appendChild(embed);
}
}
停止:
function stop123() {
var sounder = document.getElementById('firstSound');
sounder.stop();
}
相关文章推荐
- el,jstl使用
- Js中 关于top、clientTop、scrollTop、offsetTop的用法
- ♫【Underscore.js】
- JSON资料整理
- JSON.stringify 语法讲解
- JSoup真好用
- 在Java中运行javascript脚本示例
- GitHub的css/js文件给墙了的解决方法
- 数据类型和Json格式
- Javascript高级技巧分享
- AJAX初步接触
- javascript雪花效果 注释版
- JavaScript 原型 继承
- JavaScript 构造函数
- js脚本给text动态赋值,如何监听:oninput,onpropertychange的区别
- JavaScript全局函数
- JSP 禁止页面缓存,修复浏览器后退造成的权限 BUG
- js根据15,18位身份证号获取生日与性别
- js document常用的属性以及方法
- d3学习之(Data Visualization with d3.js Cookbook )(第三章)-5