-1

到现在还有 3 个小时,我正在努力解决这个问题,但现在很幸运。

我有一个页面,它的内容由几个 html 表组成,每个表都有一定的 td

它看起来像这样

<td style="padding:0px 0px 0px 5px;" valign="middle"><span class="lshevent">team a - team b </span></td>

当有人单击此 Td 在新窗口中打开整个表格时,我想将此 td 设为超链接。

我的页面源是通过文件获取内容从远程页面检索的,如下所示

<?php
    //Get the url
    $url = "http://remotesite/pages/page1.html";
    $html = file_get_contents($url);
    $doc = new DOMDocument(); // create DOMDocument
    libxml_use_internal_errors(true);
    $doc->loadHTML($html); // load HTML you can add $html

    $elements = $doc->getElementsByTagName('tbody');

    $toRemove = array();

    // gather a list of tbodys to remove
    foreach($elements as $el)
      if((strpos($el->nodeValue, 'desktop') !== false) && !in_array($el->parentNode, $toRemove, true))
        $toRemove[] = $el->parentNode;    

            foreach($elements as $el)
      if((strpos($el->nodeValue, 'Recommended') !== false) && !in_array($el->parentNode, $toRemove, true))
        $toRemove[] = $el->parentNode;  

    // remove them
    foreach($toRemove as $tbody)
      $tbody->parentNode->removeChild($tbody);

    echo str_replace('</h3><table','<table',$doc->saveHTML());
?>
4

1 回答 1

0

尝试onclick="openInNewWindow();"使用您的代码在该函数调用 ajax 中添加一个$('#<your_id>').click(function(){});andwindow.open();

抱歉,好吧,大致看起来像这样:

html -> <td id="open">或者<td onclick="openWindow();">

js:

$(function(){
   $('#open').click(function(){
      $.ajax({
         type : 'POST',
         data: {},
         dataType : 'html',
         url : '/remotesite/getSite', //here goes the link to your php function(if you are using MVC logic then it will look like this)
         success: function(data){
             myWindow=window.open('','','width=200,height=100');
             myWindow.document.write(data);
         }  
      });
   });
});

或者

function openWindow(){
   //copy the $.ajax function from above here
}

并在 php 中创建一个控制器(这取决于您的网页上是否有 MVC 逻辑,如果没有,那么您正在使用的文件的实际路径)

public function getSite(){
   //your code here and echo the template or html code where 
   //where you have your table like echo $html_code;
}

编辑:对不起,我之前没有发布代码

于 2013-05-24T05:55:46.983 回答