0

我的 el6.href 和 el7.href 不起作用,

如果我将 el6.href 和 el7.href 放在 el4.href 和 el5.href 的顶部,它可以工作,但结果是 el4。el5 不起作用,有什么提示吗?

脚本

el4 = document.getElementById("edit_href");
el5 = document.getElementById("delete_href");   
el6 = document.getElementById("approve_href");
el7 = document.getElementById("deny_href");


el4.href = "../article/submit-article.php?";        
el5.href = "myaccount.php?mydraft=true&delete=true";

el6.href = "myaccount.php?rec_approved=true&approve=true";
el7.href = "myaccount.php?rec_denied&deny=true";

php

if(isset($_GET['mydraft']))
{echo"
    < href=''  id=edit_href >edit</a>
    <a href='' id=delete_href >delete</a>";
}
if ( (isset($_GET['rec_waiting'])) || (isset($_GET['rec_denied'])) )
    {echo"  
        <a href='' id=approve_href  >approve</a>";

        if(!isset($_GET['rec_denied']))
        {echo"  
        <a href='' id=deny_href >deny </a>";
        }
    }   
4

2 回答 2

1

Javsscript代码不需要判断是否为null。因为有些元素是null。看这个。

    el4 = document.getElementById("edit_href");
    el5 = document.getElementById("delete_href");   
    el6 = document.getElementById("approve_href");
    el7 = document.getElementById("deny_href");


        if(el4!=null){
        el4.href = "../article/submit-article.php?";        
        el5.href = "myaccount.php?mydraft=true&delete=true";
    }

    if(el6!=null){
    el6.href = "myaccount.php?rec_approved=true&approve=true";
}
    if(el7!=null)
{
    el7.href = "myaccount.php?rec_denied&deny=true";
}

HTML文档是从上到下执行的。如果在javascript标签中间出现错误。所以后面的代码不会被执行

于 2012-08-07T06:40:42.113 回答
0

您必须更正您的 php 代码

if(isset($_GET['mydraft'])) 
{
    echo " 
    <a href=\"#\"  id=\"edit_href\">edit</a> 
    <a href=\"#\" id=\"delete_href\" >delete</a>"; 
} 
if (isset($_GET['rec_waiting']) || isset($_GET['rec_denied'])) 
{
    echo "   
    <a href=\"#\" id=\"approve_href\">approve</a>"; 

    if(!isset($_GET['rec_denied'])) 
    {
        echo "   
        <a href=\"#\" id=\"deny_href\">deny</a>"; 
    }
}

JS

function el(objID) {
    return document.getElementById(objID);
}

if(el('edit_href'))
    el('edit_href').href = "your_url.php";

其他网址相同

于 2012-08-07T06:28:33.153 回答