سؤال

This is my jQuery code:

$('input[name="Search"]').blur(function(e) {
    $(this).text('');
});

And my HTML snippet:

<input name="Search" type="text" id="Search" class="MainMenu" />

But it doesn't work, does anybody know why?

هل كانت مفيدة؟

المحلول 2

You are using text() on input type text which is not defined for input type=text. You need to use val()

Live Demo

$('input[name="Search"]').blur(function(e) { 
 $(this).val('');
});​

If you have id, you can use id as it will be more efficient then getting element with name selector.

Live Demo

$('#Search').blur(function(e) { 
    $(this).val('');
});​ 

نصائح أخرى

try .val() insteadof .text()

$('input[name="Search"]').blur(function(e) { 
 $(this).val('');
});​

there is no method like .text() for input type text use .val()

these change will help you

$('input[name="Search"]').blur(function(e) {
    $(this).val('');
});

or

$('#Search').blur(function(e) { 
    $(this).val('');
});​ 

Documentation here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top