RFS入门【JS脚本应用】

【JS脚本应用】
http://www.w3school.com.cn/jsref/dom_obj_document.asp
http://www.w3school.com.cn/jsref/dom_obj_all.asp

元素定位:
getElementById() 返回对拥有指定 id 的第一个对象的引用。
getElementsByName() 返回带有指定名称的对象集合。
getElementsByTagName() 返回带有指定标签名的对象集合


document.getElementsByClassName("classname")
<input type="text" id="start_date" value="2016-11-07" readonly="readonly" class="hasDatepicker">
document.getElementsByClassName("hasDatepicker")[0]

document.getElementsByTagName("tagname")

document.getElementsByClassName("classname")[0].children[0]
<div class="star-score" style="width: 140px;">
<a class="" href="javascript:void(0)" style="left: 0px; width: 28px; z-index: 5;"/>
<a href="javascript:void(0)" style="left: 0px; width: 56px; z-index: 4;"/>
<a class="" href="javascript:void(0)" style="left: 0px; width: 84px; z-index: 3;"/>
<a class="" href="javascript:void(0)" style="left: 0px; width: 112px; z-index: 2;"/>
<a class="clibg" href="javascript:void(0)" style="left: 0px; width: 140px; z-index: 1;"/>
</div>
document.getElementsByClassName("star-score")[0].children[4].getAttribute("class")

document.getElementsByClassName("order_nav_mem")[0].firstChild.children[2]

document.getElementById(id)
<input type="text" id="start_date" value="2016-11-07" readonly="readonly" class="hasDatepicker">
document.getElementById("start_date")

document.getElementsByName(name)
<input id="acc_mobile" name="mobile" type="text" maxlength="11" placeholder="请输入11位手机号码" disableautocomplete="" autocomplete="off">
document.getElementsByName("mobile")[0]

常用方法:
获取属性 .getAttribute("class")
修改属性 .setAttribute("class","1234")
移除属性 .removeAttribute("readonly")
向下滚动 .scrollTop=200

【技巧】
日后定位到某个元素,需要先手动获取元素所在页面Y位置【火狐】
再调用js滚动

猜你喜欢

转载自www.cnblogs.com/aeip/p/9066298.html
今日推荐