【问题标题】:Adding alt attribute to image in javascript在javascript中为图像添加alt属性
【发布时间】:2013-03-18 07:28:44
【问题描述】:

我想知道如何在 javascript 中为图像添加 alt 属性,下面是我的代码...

var image = document.createElement('img');
image.src='../../KY/images/common/buttons/browseIcon.png';

提前致谢。

【问题讨论】:

    标签: javascript image alt


    【解决方案1】:

    你有两种方法:你可以使用alt属性

    image.alt = "Your text here"
    

    setAttribute方法

    image.setAttribute("alt","Your text here");
    

    【讨论】:

    • "image.setAttribute("alt","你的文字在这里");"完美地满足了我的需要。谢谢!
    【解决方案2】:

    当您在 dom javascript 中创建按钮或任何其他元素时,上述方法将不起作用,为此请使用下面提到的方法

    control.setAttribute("title","your tooltip value")
    

    【讨论】:

      【解决方案3】:

      您可以使用alt property

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-09
        • 2015-02-09
        • 1970-01-01
        • 2012-11-14
        • 2016-12-24
        相关资源
        最近更新 更多