使用js在IE9中獲取標籤自定義屬性
阿新 • • 發佈:2019-02-18
JScript code
function wfMain_DevNodeContextMenu(event) {
var ele = event.target || event.srcElement;
var devType = ele.devType;
alert(devType );
}
- HTML code
-
<a id='bbbb' UserName='ccccc' href='javascript:;' devID='001' devType='525' oncontextmenu='return wfMain_DevNodeContextMenu(event)'
找了很久才發現,是ie9對自定義html標籤屬性不相容。下面的程式碼是相容的JScript codefunction wfMain_DevNodeContextMenu(event) { var ele = event.target || event.srcElement; var devType = ele.getAttribute("devType"); alert(ele.getAttribute("devType")); }
- HTML code
- <a id='bbbb' UserName