mirror of
https://github.com/jquery/jquery.git
synced 2026-02-06 14:14:56 -05:00
Make .val(undefined) == .val("") and chainable; fixes #4130.
Ensure .val(null) sets an empty string on IE6/7; fixes #5163.
This commit is contained in:
@@ -136,7 +136,7 @@ jQuery.fn.extend({
|
||||
},
|
||||
|
||||
val: function( value ) {
|
||||
if ( value === undefined ) {
|
||||
if ( !arguments.length ) {
|
||||
var elem = this[0];
|
||||
|
||||
if ( elem ) {
|
||||
@@ -209,9 +209,10 @@ jQuery.fn.extend({
|
||||
val = value.call(this, i, self.val());
|
||||
}
|
||||
|
||||
// Typecast each time if the value is a Function and the appended
|
||||
// value is therefore different each time.
|
||||
if ( typeof val === "number" ) {
|
||||
// Treat null/undefined as ""; convert numbers to string
|
||||
if ( val == null ) {
|
||||
val = "";
|
||||
} else if ( typeof val === "number" ) {
|
||||
val += "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user