我该如何使用jQuery完成这个操作?我已经使用了change事件,但是如果我提交或重置表单,文本就不会再次设置。我需要在输入框内显示一个文本(它是一个日期选择器,所以我需要显示一个日期)。
怎么做呢?
谢谢!
我该如何使用jQuery完成这个操作?我已经使用了change事件,但是如果我提交或重置表单,文本就不会再次设置。我需要在输入框内显示一个文本(它是一个日期选择器,所以我需要显示一个日期)。
怎么做呢?
谢谢!
<input type="text" placeholder="default text" />
这是我通常的做法。
<form id="myform">
<input name="box" type="text" value="Type here">
</form>
_
$("input[name='box']", "#myform").bind("blur focus", function() {
if ($(this).val() == "" ) {
$(this).val("Type here");
}else if ($(this).val() == "Type here" ) {
$(this).val("");
}
});
$('#textbox').blur(function() {
if( $('#textbox').val() == "" ) {
//show the date
}
}
你可以这样做
$(document).ready(function(){
if ($("input[id$='your textbox id']").val().length == 0 || $("input[id$='your textbox id']").val().trim() == " ") {
$("input[id$='your textbox id']").val("something");
});
实际上,你的问题不是很清楚,但是...
var yourVaribale;
$('yourTextSelector').val(yourVariable)
您可以像上面那样设置输入文本的值
$('idOfInputTextBox').writeAttribute('placeholder', theChangedDateString);
- JoJo