2012-08-07 131 views
0

我el6.href和el7.href不起作用,一些JavaScript不起作用

如果我把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>"; 
     } 
    } 

回答

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 documnet是從頂部向execution.if的底部出現在錯誤的JavaScript代碼middle.So後不會被執行

+0

感謝@Myd它的工作代碼! – 2012-08-07 06:45:12

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"; 

與其他URL相同