Jquery & Datepicker - How to protect the value of a textfield from user changes? (and automatically rerendered the value of the calendar)?
Sorry for this simple question but I am really a noob and didn't find what I want in the jquery documentation.
Here is the story:
I have a text field in a form populated by a calendar in jquery (datepicker). I would like to "protect" this textbox. in other word if the user wants to change the value in the 开发者_Python百科textbox (deleting or adding something), the value generated by the calendar is automatically re-rendered.
Thanks for your help!
HTML has the readonly attribute for textareas and input fields.
<input type="text" readonly="readonly" value="Users cannot change me" />
You could do something like this
$('#textfield-id').keydown(function(){
if($(this).val() == '') {
//get value from calendar again
var calText = $('#calendar').val();
$(this).val(calText);
}
});
精彩评论