我有一个脚本在单击按钮时随机显示文本,如何用Wordpress get_post()循环替换手动列表?
jQuery(document).ready(function ($) {
$("input[id='mantra']").keyup(function() {
$("#preview").text($("input[id='mantra']").val());
})
// I wish to substitute these variables with a list of post titles.
var randomStrings = [
"I AM DIVINE PERFECTION",
"LET GO. LET GOD.",
"FOLLOW YOUR HEART",
];
var randomDiv = document.getElementById("preview");
var changer = document.getElementById("mantra");
document.getElementById("myMantraButton").addEventListener("click", function(){
randomIndex = Math.ceil((Math.random()*randomStrings.length-1));
newText = randomStrings[randomIndex];
randomDiv.innerHTML = newText;
changer.value = newText;
});
});
提前致谢。