显示图像而不是文本Javascript函数

时间:2014-05-20 23:31:34

标签: javascript html web

可以在这些上下文中显示图像而无需主要编辑代码。通常你有:

(function() {
    popupShow("Loading...");

使用Loading ...在其中创建div弹出窗口。可能因为这是HTML div来指定要在此div而不是文本中显示的图像?原油但看起来没有重新写作就会产生一些影响:

(function() {
    popupShow(<img src="img/video.png">);

Javascript for“popupShow”

function popupShow(text, buttonText, cb) {
    var saveBoxHeight = 60;
    var saveBoxWidth  = 380;

    if ((typeof buttonText)!="undefined") {
        saveBoxHeight+=30;
    }

    disableDiv = document.createElement('div');
    disableDiv.id = "DisableDiv";
    disableDiv.className="DisableDiv";
    disableDiv.style.cssText = "position:absolute; z-index: 120";
    disableDiv.style.width = window.document.documentElement.offsetWidth + "px";
    disableDiv.style.height = window.document.documentElement.offsetHeight + "px";

    disableDiv.style.top = "0px";
    disableDiv.style.left = "0px";

    newDiv = document.createElement('div');
    newDiv.id = "PopUpDiv";
    newDiv.className="PopUpDiv";
    newDiv.style.cssText = "position:fixed;background-color:white;font-size:35px;font-family:arial;border-style:groove; border-color:blue; z-index:121";
    newDiv.style.borderWidth  = "5px";
    newDiv.style.width  = saveBoxWidth + "px";
    newDiv.style.height = saveBoxHeight + "px";
    if ($.browser.msie) {
        newDiv.style.top  = (window.document.documentElement.offsetHeight - (saveBoxHeight*1))/2 + "px";
        newDiv.style.left = (window.document.documentElement.offsetWidth - (saveBoxWidth*1))/2 + "px";
    } else {
        newDiv.style.top  = (window.innerHeight - (saveBoxHeight*1))/2 + "px";
        newDiv.style.left = (window.innerWidth - (saveBoxWidth*1))/2 + "px";
    }
    titleDiv = document.createElement('div');
    titleDiv.style.cssText = "height:25px; color:white; font-size:18px; font-family:arial; background-color:#000099; text-align:right;";

    center = document.createElement('center');
    newSpan = document.createElement('span');
    newSpan.id = "PopUpText";

    newSpan.innerHTML = text;
    center.appendChild(newSpan);

    newDiv.style.margin = "10px 10px 10px 10px";
    newDiv.style.paddingTop = "8px";
    newDiv.appendChild(center);

    if ((typeof buttonText)!="undefined") {
        button = document.createElement("input");
        button.type="button";
        button.value=buttonText;
        button.style.cssText="position:absolute;right:10px;bottom:10px;";
        if (((typeof cb)!="undefined")&&(cb!=null)) {
            button.onclick=cb;
        }
        newDiv.appendChild(button);
    }

    document.body.appendChild(newDiv);
    document.body.appendChild(disableDiv);
}

1 个答案:

答案 0 :(得分:0)

你是否试过围绕你的html img标签?

    (function() {
    popupShow('<img src="img/video.png">');
相关问题