0

我在 Javascript 中创建了自定义警报框。我添加了带有图像的文本。但它不是探针对齐。它来了这样的事情。 在此处输入图像描述

我正在尝试使用同一行添加正确的标记和文本,我该如何实现这一点。谁能帮帮我吗。我在下面添加了我的自定义警报框功能。

function createCustomAlert(txt, string_url,fd) {
        // shortcut reference to the document object
        d = document;

        // if the modalContainer object already exists in the DOM, bail out.
        if (d.getElementById("modalContainer")) return;

        // create the modalContainer div as a child of the BODY element
        mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
        mObj.id = "modalContainer";
        // make sure its as tall as it needs to be to overlay all the content on the page
        mObj.style.height = document.documentElement.scrollHeight + "px";

        // create the DIV that will be the alert 
        alertObj = mObj.appendChild(d.createElement("div"));
        alertObj.id = "alertBox";
        // MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
        if (d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
        // center the alert box
        alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth) / 2 + "px";

        // create an H1 element as the title bar
        h1 = alertObj.appendChild(d.createElement("h1"));
        h1.appendChild(d.createTextNode(ALERT_TITLE));
btn2 = alertObj.appendChild(d.createElement("img"));
        btn2.id = "fd";
        btn2.src = fd;
        // create a paragraph element to contain the txt argument
        msg = alertObj.appendChild(d.createElement("p"));
        msg.innerHTML = txt;

        // create an anchor element to use as the confirmation button.
        //btn = alertObj.appendChild(d.createElement("a"));
        //btn.id = "closeBtn";
        //btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
        //btn.href = "";


        btn = alertObj.appendChild(d.createElement("img"));
        btn.id = "closeBtn";
        btn.src = 'new-go-next2.png';
        btn.href="#ss";
        //btn.height="30px";
        //btn.width="30px";
        //btn.href="#";


        // set up the onclick event to remove the alert when the anchor is clicked
        btn.onclick = function () { removeCustomAlert(); window.location = string_url; return false; }


    }
4

2 回答 2

0

而是创建具有两列的 div 元素创建表。第一个将包含 OK 的“图像”,第二个将包含您的“文本”。检查这是否有帮助。

于 2012-10-23T08:40:43.303 回答
0

好吧,是的,创建表格将是解决您的问题的好方法,顺便说一句,您还可以尝试一些具有正确位置的内部 div 以及具有正确浮动属性的元素

于 2012-10-23T09:50:51.610 回答