How can i set random placeholder text from array of strings in jquery after document is loaded? Now i have just "hardcoded" the setting for placeholder? But how to do it dynamically?
jQuery(function($) {
$(document).ready(function () {
var list = new Array();
list.push("1");
list.push("2");
$('#search').attr("placeholder","placeholder text");
});
});
Just how one time see 1, other 2...?
$(function(){
var list = [...],
r = Math.floor(Math.random() * list.length);
$('#search').prop('placeholder',list[r]);
});
that would use any of the possibilities within list
and assign the placeholder a new random value from it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.