[英]Disabling a jquery ui dialog
我有一個jquery ui對話框,該對話框顯示在單擊按鈕時。 此對話框包含三個按鈕(真棒字體的圖標),單擊任何一個按鈕時,都會運行一個單詞列表,依次突出顯示每個單詞並播放其關聯的音頻文件。 單擊對話框中的三個按鈕之一時,必須關閉(或隱藏)對話框,以便用戶可以在基礎頁面上看到單詞列表。 這部分工作正常,但是我發現困難的是在播放任何一個單詞列表時如何禁用控制對話框的按鈕。 這對於防止同時播放多個單詞列表很有必要。 我嘗試使用一個標志-rpt_dlog_run-但我無法正確理解邏輯,但我認為這可能是錯誤的方法。 這是html:
<div id="ws_title"><p class="title_items">Word Set 1
<a class="btn_repeat" href="#"><span class="fa fa-repeat fa_repeat_ws"></span></a>
和jQuery代碼:
jQuery(document).ready(function() {
var rpt_dlog_run = false;
var ws_repeat_dlog = jQuery("div#ws_repeat_dialog").dialog({
autoOpen: false,
modal: true,
position: "center",
resizable: false,
dialogClass: "ws_repeat",
draggable: false,
create: function() {
jQuery(this).parents(".ui-dialog")
.css("border", "1px solid #0000C6")
/* ..... various other css settings ..... */
.find(".ui-dialog-header")
.css("display","none")
.css("font-size", "1.2em");
}
});
jQuery("a.btn_repeat").on("click", function(evnt) {
div#ws_title
if(!rpt_dlog_run) {
evnt.stopPropagation();
ws_repeat_dlog.dialog("open");
var modal_content ='<div id="ws_repeat_modal">
/* .... content of dialog html ....*/
</div>';
ws_repeat_dlog.append(modal_content);
jQuery("p#ws_rpt1").on("click", function (evnt) { // NB needs to be changed, move to dialog box
rpt_dlog_run = true;
evnt.stopPropagation();
ws_repeat_dlog.dialog("close");
var engWords = jQuery("span.audio"),
pathVar = document.getElementById("pathVar").innerHTML,
audioElement = document.createElement("audio"),
audioType = Modernizr.audio.ogg? ".ogg": ".mp3",
i = 0;
audioPlay(i);
audioElement.addEventListener( "ended", function() {
i = i + 2; //i++; this is a real kludge, but it will do to save time
if ( i < 100) {
jQuery.doTimeout(1500, function() {
audioPlay(i);
});
}
});
function audioPlay(i) {
var wordList = jQuery("span#"+engWords[i].id),
audioPath = pathVar+engWords[i].id+audioType;
wordList.addClass("set_font_green");
audioElement.src = audioPath;
audioElement.play();
jQuery.doTimeout(1500, function() {
wordList.removeClass("set_font_green");
});
}
rpt_dlog_run = false;
});
}
});
/* before closing, empty contents of dialog to avoid content repetition */
ws_repeat_dlog.dialog({
beforeClose: function( ) {
ws_repeat_dlog.empty();
}
});
rpt_dlog_run = false;
});
任何幫助將是最歡迎的。
解決問題,插入“ else”語句+代碼,並刪除其他設置為“ false”的標志“ rpt_dlog_run”。
if ( i < 100) {
jQuery.doTimeout(1500, function() {
hiliteTextAudioPlay(i);
});
}else{
rpt_dlog_run = false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.