my 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>";
}
}
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 标记中间出现错误。所以之后的代码不会被执行
你必须
纠正你的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";
其他网址相同