0

我正在使用此代码创建两个单独的对话框,但是当我添加第二个代码时,它仅在第一个出现时出现。这是第一个的代码:

    function showPopUp(el) {
        var cvr = document.getElementById("cover")
        var dlg = document.getElementById(el)
        cvr.style.display = "block"
        dlg.style.display = "block"
        if (document.body.style.overflow = "hidden") {
            cvr.style.width = "1024"
            cvr.style.height = "100%"
        }
    }
    function closePopUp(el) {
        var cvr = document.getElementById("cover")
        var dlg = document.getElementById(el)
        cvr.style.display = "none"
        dlg.style.display = "none"
        document.body.style.overflowY = "scroll"
    }

这是第二个的代码:

    function showPopUp2(e12) {
        var cvr = document.getElementById("cover2")
        var dlg = document.getElementById(el2)
        cvr.style.display = "block"
        dlg.style.display = "block"
        if (document.body.style.overflow = "hidden") {
            cvr.style.width = "1024"
            cvr.style.height = "100%"
        }
    }
    function closePopUp1(el2) {
        var cvr = document.getElementById("cover2")
        var dlg = document.getElementById(el2)
        cvr.style.display = "none"
        dlg.style.display = "none"
        document.body.style.overflowY = "scroll"
    }

有人可以帮忙吗?

4

2 回答 2

0

你的IF条件是错误的。你有

if (document.body.style.overflow = "hidden") {

它应该是

if (document.body.style.overflow == "hidden") {
                                  ^ see here. 

您也可以使用严格比较 ( ===)

于 2013-11-15T03:32:58.200 回答
0

请检查一下:

function showPopUp2(e12) { // its e12
    var cvr = document.getElementById("cover2")
    var dlg = document.getElementById(el2)// but you call el2 here
    cvr.style.display = "block"
    dlg.style.display = "block"
    if (document.body.style.overflow = "hidden") {
        cvr.style.width = "1024"
        cvr.style.height = "100%"
    }
}

尝试修复它。希望能帮助到你.. :)

于 2013-11-15T03:39:05.830 回答