js onclick事件不适用于td元素

时间:2018-01-03 10:44:00

标签: javascript php jquery html css

我想在使用此功能的linkdiv点击上创建弹出式div(名为linkcontent持有td 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是..

&#13;
&#13;
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."&nbsp;&nbsp;".$cname.$mpol.":</b>&nbsp;
    <font class='news_title'>".$msectname."</font><br>
    <font class='news_date'>".$moretext."</font>
  </td>
</tr>\n";
&#13;
&#13;
&#13;

我要展示的div是

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

此功能正在使用a href元素,如

<a class="jslink" href="javascript:getLinks('3975')">link</a>

但不适用于td onclick元素。 这很奇怪,因为它使用相同的功能。 任何人都知道为什么这不起作用? 感谢。

1 个答案:

答案 0 :(得分:0)

由于某些语法错误而未调用Javascript函数,请使用下面的代码更新您的PHP代码。另一件事是在你的onclick事件中你有&#34; return:false&#34;它应该是&#34;返回false&#34;

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

以及工作示例如下

&#13;
&#13;
<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&nbsp;&nbsp;TestTestMPol:</b>&nbsp;
    <font class="news_title">Test</font><br>
    <font class="news_date">More</font>
  </td>
</tr>
</table>
&#13;
private IDisposable planeSpottedSubscription;
jetfighter.PlaneSpotted.Where(x => string.Equals(x.Name, “Eurofighter”)).Subscribe(this.OnPlaneSpotted);
&#13;
&#13;
&#13;

你可以点击&#34; TestTestMPol&#34;你会看到一个警报。