【问题标题】:Grabbing onClick Value with PHP使用 PHP 获取 onClick 值
【发布时间】:2017-07-13 01:38:13
【问题描述】:

我一直在做一个小项目,我试图从 HTML 代码中获取 onClick 值。不幸的是,在阅读了一些帖子后,我应该使用 pre_match,但没有奏效。

也许有人可以在这里帮助我并帮助我找到方法?

 <div class="results">
        <table>
            <tbody><tr class="resultName">
                <td>1st</td>
                <td>2nd</td>
                <td>3rd</td>
                <td>4th</td>
                <td>&nbsp;</td>
            </tr>

                    <tr>
                        <td>1stText</td>
                        <td>2ndText</td>
                        <td>3rdText</td>
                        <td>4thText</td>
                        <td><a href="#" onclick="openWin('/link.html','Results',{width:341,height:550}); return false;">Results</a></td>
                    </tr>
        </tbody></table>
    </div>

我只能抓取文本内容“结果”。

P.s 找到了一种方法:

$linkcounter = 0;

$links = $dom->getElementsByTagName('a');

foreach ($links as $link){
                        if ($link->getAttribute('href') == "#" && $link->getAttribute('onclick')){

                            echo "linkcounter - ".$linkcounter." ".$link->getAttribute('onclick')."</br>";
                            $linkcounter++;
                        }
                    }

【问题讨论】:

    标签: php hyperlink onclick html-table href


    【解决方案1】:

    试试吧

    <a href="#" class="get_value" onclick="openWin('/link.html','Results',{width:341,height:550}); return false;">Results</a>
    

    在 JS 中

    $(function(){
     $(".get_value").click(function(){
    
       var onclickValue = $(this).attr("onclick");
     })
    })
    

    【讨论】:

    • 感谢您的意见。不幸的是,这只是 HTML 内容的一部分,里面有很多“tr”内容,我想将所有这些数据动态解析到我的服务器。文本部分已完成,不幸的是在 onClick 部分中挣扎..
    • OP 没有标记 JQuery,也没有在问题中发布任何 jquery 代码,因此即使 jquery 可能是一个可行的解决方案,您也应该坚持使用纯 Javascript。
    【解决方案2】:

    PHP 无法“点击”获取值。那将是 JavaScript。 PHP 只能获取通过 $_POST 或 $_GET 传递的值。

    http://php.net/manual/en/reserved.variables.post.php http://php.net/manual/en/reserved.variables.get.php

    【讨论】:

      猜你喜欢
      • 2010-11-27
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多