我编写了 jquery 代码来分别指定英文单词列表。 我使用HTML音频“on ended”事件发出下一个单词,如下面的代码所示。
$("#PlaySnd").on('ended', function(e) {
// start:
var crnt = $("img[src$='../Images/checked.png']");
crnt.closest('tr').next().find('.chck').attr('src', '../Images/checked.png');
crnt.attr('src', '../Images/Unchecked.png');
crnt = $("img[src$='../Images/checked.png']");
var thisword = crnt.parent().parent().children(0).children(0).html();
if (/\s/.test(thisword)) {
//alert('it has space');
// here I would like to start code from the bigenning like this
// GoTo stat
// because some words hase more than one word so it causes progrm stop so I need to move to the next one
} else {
$("#PlaySnd").attr('src', 'https://ssl.gstatic.com/dictionary/static/sounds/oxford/' + thisword + '--_gb_1.mp3').trigger('play');
} // end if
});
如评论中所示,我需要做一些像VBA“ GoTo ”这样的事情,以便继续执行程序并防止停止。
答案 0 :(得分:0)
js中没有goto
语句,但有一些解决方法。使用带标签虽然效果很好,但我认为:
$("#PlaySnd").on('ended', function (e) {
start: while(true) {
var crnt = $("img[src$='../Images/checked.png']");
crnt.closest('tr').next().find('.chck').attr('src', '../Images/checked.png');
crnt.attr('src', '../Images/Unchecked.png');
crnt = $("img[src$='../Images/checked.png']");
var thisword = crnt.parent().parent().children(0).children(0).html();
if (/\s/.test(thisword)) {
//alert('it has space');
// here I would like to start code from the bigenning like this
continue start
// because some words hase more than one word so it causes progrm stop so I need to move to the next one
}
else {
$("#PlaySnd").attr('src', 'https://ssl.gstatic.com/dictionary/static/sounds/oxford/' + thisword + '--_gb_1.mp3').trigger('play');
} // end if
break; // break when reaching end
} // end start labeled while
});