When I try to set a text input to blank (when clicked) using $(this).value=""
, this does not work. I have to use $(this).val('')
.
Why? What is the difference? What is the mechanism behind the val
function in jQuery?
$(document).ready(function() {
$('#user_name').focus(function(){
$(this).val('');
});
});
// error code: not working...
$(document).ready(function() {
$('#user_name').focus(function(){
$(this).value='';
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…