javascript – 是否无法在title属性中使用HTML实体?

前端之家收集整理的这篇文章主要介绍了javascript – 是否无法在title属性中使用HTML实体?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
上面的screengrab来自Firefox.光标悬停在图像左侧的黄点上.这是< img>元素(实际上它是一个图像与包含单个圆形< area>元素的图像映射,但我认为这种区别是不重要的)已经在 JavaScript中创建和设置样式,包括应用title属性(通过切割构造)和胶合弦).我怎样才能让它表现出来并显示出预定的角色,而不是& ndash;?它适用于innerHTML(左上角的文本“Barrow-In-Furness”是一个div,也是使用JavaScript创建的,以及它的innerHTML集.)

编辑:回答Domenic的问题:这是构建和应用title属性的JavaScript函数(除了执行其他作业):

var StyleLinkMarker = function (LinkNumber,EltA,EltI) {
    var AltText = LocationName[LinkStart[LinkNumber]] +
                  " to " +
                  LocationName[LinkEnd[LinkNumber]];
    if (!EltA) {
        EltA = document.getElementById("link_marker_area" + LinkNumber);
        EltI = document.getElementById("link_marker_img" + LinkNumber);
    }
    if (LinkStatus[LinkNumber] === 9) {
        var CanBuyLinkCode = BoardPreviewmode ? 0 : CanBuyLink(LinkNumber);
        if (CanBuyLinkCode === 0) {
            EltI.src = ImagePath + "icon-buylink-yes.png";
            AltText += " (you can buy this " + LinkAltTextDescription + ")";
        } else {
            EltI.src = ImagePath + "icon-buylink-no.png";
            AltText += " (you cannot buy this " + LinkAltTextDescription;
            AltText += CanBuyLinkCode === 1 ?
                       ",because you aren't connected to it)" :
                       ",because you would have to buy coal from the Demand Track,and you can't afford to do that)";
        }
    } else if ( LinkStatus[LinkNumber] === 8 ||
                (LinkStatus[LinkNumber] >= 0 && LinkStatus[LinkNumber] <= 4)
                ) {
        EltI.src = ImagePath + "i" + LinkStatus[LinkNumber] + ".png";
        if (LinkStatus[LinkNumber] === 8) {
            AltText += " (orphan " + LinkAltTextDescription + ")";
        } else {
            AltText += " (" +
                       LinkAltTextDescription +
                       " owned by " +
                       PersonReference(LinkStatus[LinkNumber]) +
                       ")";
        }
    } else {
        throw "Unexpected Link Status";
    }
    EltA.alt = AltText;
    EltA.title = AltText;
};

LocationName如下:

var LocationName = [
    "Barrow&ndash;In&ndash;Furness","Birkenhead","Blackburn","Blackpool","Bolton","Burnley","Bury","Colne","Ellesmere Port","Fleetwood","Lancaster","Liverpool","Macclesfield","Manchester","The Midlands","Northwich","Oldham","Preston","Rochdale","Scotland","Southport","Stockport","Warrington &amp; Runcorn","Wigan","Yorkshire"
];

解决方法

您没有设置title属性,您正在设置title属性,该属性需要文本而不是HTML(尽管setAttribute方法也需要文本字符串).

一般来说,在处理DOM操作时,您提供的是文本,而不是HTML. .innerHTML是这条规则的值得注意的例外.

原文链接:https://www.f2er.com/js/157780.html

猜你在找的JavaScript相关文章