0

我需要在内容加载后监听添加到视频标签的controls="controls"属性,即通过用户操作 DOM。

这样做的原因是因为我有一组自定义控件,并且不希望人们重新添加默认控件值。

我尝试了几件事:

$(document).ready(function(){
    $('#vidplayer').live(function(){
        var attr = $(this).attr('controls');
        if(attr)
        {
            $(this).removeAttr('controls');
        }
    });
});

$(document).ready(function(){
    $('#vidplayer').change(function(){
        var attr = $(this).attr('controls');
        if(attr)
        {
            $(this).removeAttr('controls');
        }
    });
});

我对事件监听做了很多研究,但我很难理解它,我希望这里的人有知识可以提供帮助!

视频标签的 ID 是#vidplayer

除此之外,如果有人知道一起禁用控件或禁用全屏模式的方法,那么这同样有用!

希望我已经完全解释了自己。

提前致谢

4

1 回答 1

0

如果您不想诉诸轮询机制(带有定期检查的 setInterval),则必须使用已弃用的突变事件(DOMAttrModified),因为它们会杀死浏览器性能或大多数浏览器中尚未实现的突变观察者.

我不能在这里测试它,因为我的浏览器(chrome)还没有实现它们。但事情应该是这样的:

// select the target node
var target = document.getElementById('videoelement');

// create an observer instance
var observer = new MutationObserver(function(mutations) {
    $(target).removeAttr('controls');
});

// configuration of the observer:
var config = { attributes: true, childList: false, characterData:   false }

// pass in the target node, as well as the observer options
observer.observe(target, config);
于 2012-09-18T16:41:50.810 回答