function zhuanhuan() {
if (document.getElementById("txtJSON").value == "") {
alert('请输入单词!'); //判断txtJson元素输入是否为空白
} else {
$(".display").empty(); var words =$('#txtJSON').val().split("\n"); //以换行符分割txtJson元素的字符串到words数组
for (i = 0; i < words.length; i++) {
$(".display").append("<div class='word'><a class='" + words[i] + "' onclick='pronance(this)'>" +
words[i] + "</a></div>");添加若干个div
$("button#dictation").click(function () { var childs =$(".display").find("div > a"); //
var pn = document.getElementsByName("proun");
var p = 1;
for (n = 0; n < pn.length; n++) {
if (pn[n].checked) {
p = pn[n].value; //获取上面函数的生成的div的value属性
}
}
var i = 0;
var t = document.getElementById("time").value;
function myloop() {
setTimeout(function () {
var audio = $("#audio");
audio.attr("src", "http://dict.youdao.com/dictvoice?audio=" + $(childs[i]).attr("class") +
"&type=" + p);
audio.get(0).play();//GET有道词典的音频外链地址 获取音频文件
i++;
if (i < childs.length) {
myloop();
}
}, 1000 * t);
}
myloop();
});
|