How to check element existence using its alias attributes with Mootools
How to check element existence using its alias attributes with Mootools
Tried as follows. But its not working,
<select alias="school_type" id="15_4_19" name="15_4_19">
<option label="" value="">Select</option>
<op开发者_StackOverflow中文版tion selected="selected" label="High School" value="8">High School</option>
<option label="University" value="9">University</option>
<option label="Elementary Schools" value="10">Elementary Schools</option>
</select>
if($$('select[alias=school_type]'))
{
var elv = $$('select[alias=school_type]');
var schoolType = elv[0].id;
data['type_id'] = $(schoolType).get('value');
}
Any help please
$$
was sort of an alias for document.getElements
(or Slick.find
now) and will always return a HTML collection--even when with 0 members. hence, the if ($$())
assertion will not be falsy.
either do if ($$('selector').length)
or if (document.getElement('select[alias=foo]'))
instead, which will be null
or element object
so will evaluate falsy
Rewrite this to:
var selectEl = document.getElement('select[alias=school_type]');
if (selectEl) {
data['type_id'] = selectEl.get('value');
}
精彩评论