无法在 IE 9 中传递此运算符的值,而它在 IE7 和 IE8 中工作正常

Unable to pass value of this operator in IE 9 while it is working fine in IE7 and IE8

本文关键字:IE7 IE8 工作 IE 运算符      更新时间:2023-09-26

我无法使用此运算符将对象传递给 loadApp() 来使用div 标签的属性

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<script>
function loadApp(theItem)
{
_thePage = theItem.appname;
alert(_thePage);// displaying undefined value in IE 9 while it works in IE7 and IE8(../eisptool.html)
}
</script>
</head>

在正文中,我们有一个具有以下属性的div 标签:

<div class="treeItem" onclick="setGroup('graph');loadApp(this)" fex="GSAS"   appname="../eisptool.html" show="domainView calculationRule target" hide="trigger">Summary Graph</div>

当我尝试使用div 标签的 appname 属性时,我得到未定义的值。

某些属性会自动转换为浏览器的属性,例如 .id 。 但是,自定义属性通常不会转换为属性,因此如果要在所有浏览器中读取自定义属性,则需要使用 .getAttribute() 读取它。

function loadApp(theItem) {
    _thePage = theItem.getAttribute("appname");
    alert(_thePage);
}

当然,您确实应该将HTML5规范用于自定义属性并使用data-前缀,以便HTML中的自定义属性data-appname="../eisptool.html"并且您将使用getAttribute("data-appname")