开发者

How to check element existence using its alias attributes with Mootools

开发者 https://www.devze.com 2023-03-10 17:57 出处:网络
How to check element existence using its alias attributes with Mootools Tried as follows. But its not working,

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');
}
0

精彩评论

暂无评论...
验证码 换一张
取 消