5 ], function( jQuery
, support
) {
10 val: function( value
) {
11 var hooks
, ret
, isFunction
,
14 if ( !arguments
.length
) {
16 hooks
= jQuery
.valHooks
[ elem
.type
] || jQuery
.valHooks
[ elem
.nodeName
.toLowerCase() ];
18 if ( hooks
&& "get" in hooks
&& (ret
= hooks
.get( elem
, "value" )) !== undefined ) {
24 return typeof ret
=== "string" ?
25 // handle most common string cases
26 ret
.replace(rreturn
, "") :
27 // handle cases where value is null/undef or number
28 ret
== null ? "" : ret
;
34 isFunction
= jQuery
.isFunction( value
);
36 return this.each(function( i
) {
39 if ( this.nodeType
!== 1 ) {
44 val
= value
.call( this, i
, jQuery( this ).val() );
49 // Treat null/undefined as ""; convert numbers to string
52 } else if ( typeof val
=== "number" ) {
54 } else if ( jQuery
.isArray( val
) ) {
55 val
= jQuery
.map( val
, function( value
) {
56 return value
== null ? "" : value
+ "";
60 hooks
= jQuery
.valHooks
[ this.type
] || jQuery
.valHooks
[ this.nodeName
.toLowerCase() ];
62 // If set returns undefined, fall back to normal setting
63 if ( !hooks
|| !("set" in hooks
) || hooks
.set( this, val
, "value" ) === undefined ) {
73 get: function( elem
) {
74 var val
= jQuery
.find
.attr( elem
, "value" );
78 // option.text throws exceptions (#14686, #14858)
79 jQuery
.trim( jQuery
.text( elem
) );
83 get: function( elem
) {
85 options
= elem
.options
,
86 index
= elem
.selectedIndex
,
87 one
= elem
.type
=== "select-one" || index
< 0,
88 values
= one
? null : [],
89 max
= one
? index
+ 1 : options
.length
,
94 // Loop through all the selected options
95 for ( ; i
< max
; i
++ ) {
96 option
= options
[ i
];
98 // oldIE doesn't update selected after form reset (#2551)
99 if ( ( option
.selected
|| i
=== index
) &&
100 // Don't return options that are disabled or in a disabled optgroup
101 ( support
.optDisabled
? !option
.disabled
: option
.getAttribute("disabled") === null ) &&
102 ( !option
.parentNode
.disabled
|| !jQuery
.nodeName( option
.parentNode
, "optgroup" ) ) ) {
104 // Get the specific value for the option
105 value
= jQuery( option
).val();
107 // We don't need an array for one selects
112 // Multi-Selects return an array
113 values
.push( value
);
120 set: function( elem
, value
) {
121 var optionSet
, option
,
122 options
= elem
.options
,
123 values
= jQuery
.makeArray( value
),
127 option
= options
[ i
];
129 if ( jQuery
.inArray( jQuery
.valHooks
.option
.get( option
), values
) >= 0 ) {
132 // When new option element is added to select box we need to
133 // force reflow of newly added node in order to workaround delay
134 // of initialization properties
136 option
.selected
= optionSet
= true;
140 // Will be executed only in IE6
145 option
.selected
= false;
149 // Force browsers to behave consistently when non-matching value is set
151 elem
.selectedIndex
= -1;
160 // Radios and checkboxes getter/setter
161 jQuery
.each([ "radio", "checkbox" ], function() {
162 jQuery
.valHooks
[ this ] = {
163 set: function( elem
, value
) {
164 if ( jQuery
.isArray( value
) ) {
165 return ( elem
.checked
= jQuery
.inArray( jQuery(elem
).val(), value
) >= 0 );
169 if ( !support
.checkOn
) {
170 jQuery
.valHooks
[ this ].get = function( elem
) {
172 // "" is returned instead of "on" if a value isn't specified
173 return elem
.getAttribute("value") === null ? "on" : elem
.value
;