我有一个场景,这个功能齐全的按钮名为btnRemove,
player.onTracksChanged_ = function(event) {
// Update the track lists.
var lists = {
video: document.getElementById('videoTracks'),
audio: document.getElementById('audiotrackButton'),
text: document.getElementById('captionButton')
};
var formatters = {
video: function(track) {
return track.width + 'x' + track.height + ', ' +
track.bandwidth + ' bits/s';
},
audio: function(track) {
return 'language: ' + track.language + ', ' +
track.bandwidth + ' bits/s';
},
text: function(track) {
return 'language: ' + track.language + ' ' +
'(' + track.kind + ')';
}
};
// Clear the old track lists.
Object.keys(lists).forEach(function(type) {
var list = lists[type];
while (list.firstChild) {
list.removeChild(list.firstChild);
}
});
// Populate with the new tracks.
var tracks = player.getTracks();
tracks.sort(function(t1, t2) {
// Sort by language, then by bandwidth.
if (t1.language) {
var ret = t1.language.localeCompare(t2.language);
if (ret) return ret;
}
return t1.bandwidth - t2.bandwidth;
});
tracks.forEach(function(track) {
var list = lists[track.type];
var option = document.createElement('option');
option.textContent = formatters[track.type](track);
option.track = track;
option.value = track.id;
option.selected = track.active;
list.appendChild(option);
});
};
现在我想这样做,以便当按下 DELETE -key时,触发btnRemove按钮并删除焦点中的项目/所选元素。
以下是代码:
var mediaTracks = player.getTracks();
if (mediaTracks.length >= 2) {
console.log('there are more than 2 tracks');
} else {
console.log('there are less than 2 tracks');
};
当我运行它时,每当我按 DELETE 时,控制台都会输出 DELETE ,但它不会输出“ ATTEMPT ---- “在那之后。
我认为没有任何理由不应该触发
是什么?
答案 0 :(得分:2)
您正在尝试将KeyCode
与String
进行比较。将条件更改为 -
if (KeyCode.DELETE == event.getCode()) { ... }
你在第一个println
看到的是KeyCode的toString,它显然返回了它的名字。