解決方案: 腳本:
$(document).ready(function(){
if(!Modernizr.input.placeholder){ //placeholder
makePlaceholders();
}//if
if(!Modernizr.input.autofocus){ //auto focus
$("input[autofocus]").focus();
}//if
if(!Modernizr.inputtypes.number){ //number spinner
var $numerics = $("input[type=number]");
$numerics.each(function(){
var thisNum = $(this);
thisNum.spinner({
min: thisNum.attr("min"),
max: thisNum.attr("max"),
step: thisNum.attr("step")
});
});
}//if
if(!Modernizr.inputtypes.date){ //date input
var $dates = $("input[type=date]");
$dates.each(function(){
var thisDate = $(this);
thisDate.datepicker({
minDate: thisDate.attr("min"),
maxDate: thisDate.attr("max"),
dateFormat: "yy-mm-dd"
});
});
}//if
});//document.ready
function makePlaceholders(){
$inputs = $("input[type=text],input[type=email],input[type=tel],input[type=url]");
$inputs.each(
function(){
var $this = jQuery(this);
this.placeholderVal = $this.attr("placeholder");
$this.val(this.placeholderVal);
}
)//each
.bind("focus", function(){
var $this = jQuery(this);
var val = $.trim($this.val());
if(val == this.placeholderVal || val == ""){
$this.val("");
}//if
})//bind
.bind("blur", function(){
var $this = jQuery(this);
var val = $.trim($this.val());
if(val == this.placeholderVal || val == ""){
$this.val(this.placeholderVal);
}//if
});//bind
}//function
</script>
的HTML:
<input type="number" min="6" max="30" step="1" value ="6">
希望這可以幫助別人。
您是否包含了所有需要的庫? – epascarello
'$ .ui'是jQuery UI的命名空間。即使在你的教程中,它說,*爲了給其他瀏覽器提供回退,我們將使用jQuery UI的滑塊小部件。*您需要包含它。 – Ohgodwhy
我沒有包含jquery ui。我發現這個[http://forrst.com/posts/HTML5_Forms_Code-sjI](http://forrst.com/posts/HTML5_Forms_Code-sjI),它的功能,除了CSS,我想我應該包括。謝謝 – rakela