I want to add a button on my wordpress page. When the user click on it, the text box above that button show a random number between 1-10000
I am quite new to Wordpress, I want to integrate some scripts to my Wordpress site to do this random number generation. For example I can call a php function when clicking that button. And the php code helps generate that random number and put it on the text box. but I don’t know where to begin. I googled that, but there isn’t a good reference for beginners at all
I want to add a button on my wordpress page. When the user click on it, the text box above that button show a random number between 1-10000
I am quite new to Wordpress, I want to integrate some scripts to my Wordpress site to do this random number generation. For example I can call a php function when clicking that button. And the php code helps generate that random number and put it on the text box. but I don’t know where to begin. I googled that, but there isn’t a good reference for beginners at all
Share Improve this question asked Dec 9, 2019 at 4:57 gudakogudako 1113 bronze badges2 Answers
Reset to default 1all thing you have to do is use javaScript function
JavaScript Example:
var random_number = function(){
return Math.floor(Math.random() * 10000) + 1;
};
document.getElementById('button_text').onclick = function () {
document.getElementById("input_box").innerHTML = random_number();
};
jQuery Example:
$.randomBetween(0,10000);
In Jquery we can written as,
jQuery('body').on('click', '#button_text',function(){
var minNumber = 1;
var maxNumber = 10000;
var randomNumber = randomNumberFromRange(minNumber, maxNumber);
jQuery('#input_box').val() = randomNumber;
});
function randomNumberFromRange(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744925914a4601434.html
评论列表(0条)