我在這裏找到了這段偉大的代碼:(http://jsfiddle.net/bzBzL/) 我想在我的Wordpress頁面中使用它(我可能需要它在一頁以上)。我完全不熟悉Javascript和Wordpress Codex在這方面沒有多大幫助。 (https://codex.wordpress.org/Using_Javascript) 我需要在哪裏插入下面的代碼? 謝謝你們。 我的網站:www.visionmars.com在wordpress頁面中加載javascript
var timer, fullText, currentOffset, onComplete;
function Speak(person, text, callback) {
$("#name").html(person);
fullText = text;
currentOffset = 0;
onComplete = callback;
timer = setInterval(onTick, 100);
}
function onTick() {
currentOffset++;
if (currentOffset == fullText.length) {
complete();
return;
}
var text = fullText.substring(0, currentOffset);
$("#message").html(text);
}
function complete() {
clearInterval(timer);
timer = null;
$("#message").html(fullText);
onComplete();
}
$(".box").click(function() {
complete();
});
Speak("Simon",
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
function() {
setTimeout(function(){
Speak("Javascript", "Simon has finished speaking!");
}, 2000);
});
jQuery代碼將無法正常工作與jQuery的附帶的WordPress。請參閱[關於jQuery noConflict Wrappers的文檔](http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers)。 –