我想创建一个弹出div(命名为linkdiv
按住linkcontent
div),点击这个函数:
function getLinks(lid) {
document.getElementById('linkdiv').style.display = "block";
document.getElementById('linkdiv').style.visibility = "visible";
document.getElementById('linkcontent').innerHTML = "<div align=center><img src='images/spacer.gif' border=0 height=280 width=10 alt=''><br><img src='images_v2/loading.gif' border=0 alt='Loading content'></div>";
var lurl = "viewlinksdiv.php?lid="+lid;
if(window.XMLHttpRequest) {
reql = new XMLHttpRequest;
} else if(window.ActiveXObject) {
reql = new ActiveXObject("Microsoft.XMLHTTP");
}
if(reql) {
reql.onreadystatechange = getLinkResp;
reql.open("GET",lurl,true);
reql.send(null);
} else {
alert("Your browser does not support XMLHttpRequest technology!");
doesNotSupport = false;
}
}
而
td
是。。echo "
<tr>
<td width=240 height=20 align=\ "left\" valign=\ "top\" style=\ "cursor:hand;cursor:pointer;padding-top:".$pad. ";padding-bottom:5px\" onclick=\ "getLinks('".$mid. "');return:false;\"><b class='news_date'>".$mdate." ".$cname.$mpol.":</b>
<font class='news_title'>".$msectname."</font><br>
<font class='news_date'>".$moretext."</font>
</td>
</tr>\n";
我想展示的是
<div id="linkdiv">
<div id="linkdiv_body">
<div id="tapclose" align="right" onclick="closeLink()" alt="Close">X</div>
<div id="linkcontent" class="linkdiv_font"></div>
</div>
</div>
此函数用于
td
元素<a class="jslink" href="javascript:getLinks('3975')">link</a>
但对
a href
td
元素不起作用。这很奇怪,因为它使用相同的函数。
有人知道为什么这不管用吗?
谢谢。
最佳答案
由于某些语法错误,无法调用Javascript函数,请使用下面的代码更新php代码。另一件事是在onclick事件中,您有“return:false”应该是“return false”
echo "
<tr>
<td width=240 height=20 align='left' valign='top' style='cursor:hand;cursor:pointer;padding-top:".$pad. ";padding-bottom:5px' onclick=\"getLinks('".$mid. "');return false;\"><b class='news_date'>".$mdate." ".$cname.$mpol.":</b>
<font class='news_title'>".$msectname."</font><br>
<font class='news_date'>".$moretext."</font>
</td>
</tr>\n";
工作示例如下
function getLinks(lid) {
alert("called");
document.getElementById('linkdiv').style.display = "block";
document.getElementById('linkdiv').style.visibility = "visible";
document.getElementById('linkcontent').innerHTML = "<div align=center><img src='images/spacer.gif' border=0 height=280 width=10 alt=''><br><img src='images_v2/loading.gif' border=0 alt='Loading content'></div>";
var lurl = "viewlinksdiv.php?lid="+lid;
if(window.XMLHttpRequest) {
reql = new XMLHttpRequest;
} else if(window.ActiveXObject) {
reql = new ActiveXObject("Microsoft.XMLHTTP");
}
if(reql) {
reql.onreadystatechange = getLinkResp;
reql.open("GET",lurl,true);
reql.send(null);
} else {
alert("Your browser does not support XMLHttpRequest technology!");
doesNotSupport = false;
}
}
<table>
<tr>
<td style="cursor:hand;cursor:pointer;padding-top:10;padding-bottom:5px" onclick="getLinks('9999');return false;" width="240" valign="top" height="20" align="left"><b class="news_date">1/1/2017 TestTestMPol:</b>
<font class="news_title">Test</font><br>
<font class="news_date">More</font>
</td>
</tr>
</table>
您可以点击“TestTestMPol”,就会看到一个警报。
关于javascript - js onclick事件不适用于td元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48075786/