【发布时间】:2010-11-15 04:17:49
【问题描述】:
我正在构建一个小型 Web 应用程序来运行 MIDI 文件。目前我正在使用快速时间来播放 MIDI 文件。问题是我不知道我需要将对象绑定到什么来源,直到用户输入一些信息(比如搜索)。我需要能够将快速电影更新到正确的路径。可能吗? ajax 支持吗?
【问题讨论】:
标签: javascript html ajax
我正在构建一个小型 Web 应用程序来运行 MIDI 文件。目前我正在使用快速时间来播放 MIDI 文件。问题是我不知道我需要将对象绑定到什么来源,直到用户输入一些信息(比如搜索)。我需要能够将快速电影更新到正确的路径。可能吗? ajax 支持吗?
【问题讨论】:
标签: javascript html ajax
AJAX 是一种技术。您要做的是使用 JavaScript 更改 QuickTime 电影路径。
var qtMovie=document.getElementById('yourMovieEmbedID');
qtMovie.src='your new source';
您应该将此代码包装在一个函数中,并在用户单击“确定”按钮时运行它。
【讨论】:
如果您确实需要添加 <param>(而不是调整属性值),我发现抓取 <object>,克隆它,添加 <param> 和然后替换当前的<object> 标签似乎在大多数浏览器中都有效(尽管它似乎在 Firefox 中无效)。有关工作示例,请参阅 this answer。
链接的答案适用于页面上的每个<object>,以下是针对单个标签实例的方法:
// create the appropriate <param>
var elementToAppend = document.createElement('param');
elementToAppend.setAttribute('name', 'src');
elementToAppend.setAttribute('value', 'blah.midi');
// get a reference to the <object>
var obj = document.getElementById('yourMidiPlayerObject');
// duplicate the <object>
var newObj = obj.cloneNode(true);
// append the <param> to the <object>
newObj.appendChild(elementToAppend);
// replace the <object> on the page
obj.parentNode.replaceChild(newObj, obj);
如果你要修改的<param>已经存在,那就有点不一样了:
// get a reference to the <object>
var obj = document.getElementById('yourMidiPlayerObject');
// duplicate the <object>
var newObj = obj.cloneNode(true);
// get a reference to the current <param>
var param = document.getElementById('theParamId');
// duplicate the <param>
var newParam = param.cloneNode(true);
// change the value of the <param>
newParam.setAttribute('value', 'newblah.midi');
// replace the <param> tag on the <object>
newObj.replaceChild(newParam, param);
// replace the <object> on the page
obj.parentNode.replaceChild(newObj, obj);
在这两种情况下,让它在 IE、Opera、Safari 和 Chrome 中运行的技巧是替换页面上的<object>。将新的<param> 附加到现有的<object> 似乎不会使其重新解析值或加载新引用的内容。
【讨论】: