基于chrome操作的方式越来越多,但多大数模块或者支持库并不是很完善,收集了一些MDN方法可以参考下。 方法中
[path]
代表选择器路径,[value]
代表传入值,[name]
代表属性名,true|false
代表是否选中,%d
代表引索。
元素取值
document.querySelector([path]).value
元素置值
document.querySelector([path]).value=[value]
元素取文本
document.querySelector([path]).innerText
元素置文本
document.querySelector([path]).innerText=[value]
元素取HTML
document.querySelector([path]).innerHTML
元素置HTML
document.querySelector([path]).innerHTML=[value]
元素取属性值
document.querySelector([path]).getAttribute([name])
元素置属性值
document.querySelector([path]).setAttribute([name],[value])
元素事件
document.querySelector([path]).event()
元素移出焦点
document.querySelector([path]).blur();
元素获得焦点
document.querySelector([path]).focus();
元素点击
document.querySelector([path]).click();
元素选择
document.querySelector([path]).checked=true|false;
SELECT_取列表数
document.querySelector([path]).length;
SELECT_取选中表项
document.querySelector([path]).selectedIndex;
SELECT_置选中表项
document.querySelector([path]).selectedIndex=%d;
SELECT_取表项文本
document.querySelector([path]).options[%d].text
FORM_取地址
document.querySelector([path]).action
FORM_置地址
document.querySelector([path]).action
FORM_重置
document.querySelector([path]).reset()
FORM_提交
document.querySelector([path]).submit()
TABLE_取行数
document.querySelector([path]).rows.length
TABLE_取列数
document.querySelector([path]).rows[%d].cells.length
TABLE_取单元格文本
document.querySelector('%s').rows[%d].cells[%d].innerText
TABLE_取单元格源码
document.querySelector('%s').rows[%d].cells[%d].innerHTML
置滚动条距离
window.scrollBy(%d,%d)
置滚动条位置
window.scrollTo(%d,%d)