Why is this MooTools Javascript not working in IE
All I want to do is create an input with an initialised value. Then when focused it clears the text field. however on blur and when the field is empty it should return its initialised value. It should also work with password fields. This is what i came up with its not working in ie.
Error message
$$('.default-text').each(funct开发者_C百科ion(item){
item.store('default-value', item.get('value'));
if(item.get('type') == 'password') {
item.store('default-type', 'password');
item.set('type', 'text');
item.addEvent('keyup',function(el){
if(item.get('value') != item.retrieve('default-value')) {
item.set('type', 'password');
}
});
}
item.addEvent('focus',function(el){
if(item.get('value') == item.retrieve('default-value')) {
item.set('value','');
}
});
item.addEvent('blur',function(){
if(item.get('value') == '') {
item.set('value', item.retrieve('default-value'));
if(item.retrieve('default-type') == 'password') {
item.set('type', 'text' );
}
}
});
});
IE has a problem with swapping input.type
properties.
Swapping between types just does not appear work, if I remember correctly - which I think they did to save themselves some grief.
Eg, change a text
field to a file
field has security implications, field.set("value", "c:\autoexec.bat").set("type", "file").getParent().send()
.
change password
to text
, also dodgy (would reveal password in plain text). change text
to checkbox
/radio
has reflow and behaviour issues.
I can continue but IE team just thought it best to not allow these and put an end to them, rather than deal with each case.
You need to rethink your logic somewhat.
精彩评论