[英]simplehtmldom get input onclick
現在我發瘋了,我試圖在幾個小時內獲得輸入元素的onclick屬性。
正在收到以下錯誤:
Notice: Trying to get property of non-object in C:\wamp\www\glitcher\ab.php on line 6
這是代碼段:
<?php
include 'simple_html_dom.php';
$content='<input type="button" onclick="s8Ajax(\'/bounty.php?hitlist_id=32234066&formNonce=166f7ddc73ce8024c3a6a2b894fa0c83a3d5272c&setTab1Badge=&h=891173dbc0c1aef4bec8592a7e3e74306efa7065\')" class="btnMed" style="font-size: 15px;" value="Add to Hit List">';
$content=str_get_html($content);
$href=$content->find('.btnMed');
$href=$href->onclick;
echo $href;
?>
提前致謝
find()函數返回一個dom對象數組,因此您必須指定要處理的元素的索引。
所以要么使用: $href = $content->find('.btnMed', 0);
wich將檢索數組的第一個元素,在這種情況下$ href是一個對象...
或者,由於$ href是一個數組,因此在他的第一個對象元素上調用onclick屬性,如下所示: $href = $href[0]->onclick;
這是一個完整的工作示例:
$text = '<input type="button" onclick="s8Ajax(\'/bounty.php?hitlist_id=32234066&formNonce=166f7ddc73ce8024c3a6a2b894fa0c83a3d5272c&setTab1Badge=&h=891173dbc0c1aef4bec8592a7e3e74306efa7065\')" class="btnMed" style="font-size: 15px;" value="Add to Hit List">';
//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($text);
// Find the first elements with class 'btnMed'
$btn = $html->find('.btnMed', 0);
// Find succeeded
if ($btn) {
$href = $btn->onclick;
echo $href;
}
else
echo "Find function failed !";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.