我的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>";
}
}
答案 0 :(得分: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是执行的从上到下。如果在javascript标签中出现错误,那么之后的代码将不会被执行
答案 1 :(得分: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";
其他网址相同