我有一个问题要问。
我有一个基于从 MySQL 数据库检索的数据的搜索结果。根据检索到的数据,我嵌入并回显了 div 和 <a>
标签知道是哪个<a>
单击后,我可以使用 searchresult_details.php 使用 ajax jQuery 检索更多详细信息。
<?php
//include database connection file to call the class
include('dbconn.php');
//db global connection
$db = new DBConfig();
$db -> config();
$db -> conn();
//retrieve the keyword entered in the form in search.php
$keyword = $_POST['keyword'];
//call searchKeyValue method to retrieve the names whether client or staff
searchKeyValue($keyword);
function searchKeyValue($keyword)
{
$result = mysql_query("SELECT result_key, result_value FROM keyvalue WHERE result_value LIKE '%$keyword%'");
while($row = mysql_fetch_array($result)){
//echo $row['result_value'];
//echo "<br />";
echo '<div style="background-color:#ffa; padding:20px"><a class="record" value="' . $row['result_value'] . '">' . $row['result_value'] . '</a>' . '</div>';
echo '<input class="tablename" type="hidden" name="tablename" value="' . $row['result_key'] . '" />';
}
}
?>
但是,<a>
将有多行被回显。我需要检索<a>
单击的值以及存储在该特定 <a>
中的值元素。我无法在 <a>
中使用 id因为我认为这会很乏味。我正在考虑使用类,以便在 javascript 中我可以使用 document.getElementsByClassName 但我知道 IE 中的此类函数有错误。
有什么建议吗?
最佳答案
请检查 jQuery 类选择器
关于php - 如何使用从 MySQL 检索的数据通过 .click jQuery 函数检索 html 元素值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550814/