如何通过.click jQuery函数检索html元素值与从MySQL检索的数据?
I have a question to ask.
我有一个问题要问。
I have a search result that is based on data retrieved from MySQL database. And based on the data retrieved, I have embedded and echo a div and <a>
tag to know which <a>
is been clicked so that I can use searchresult_details.php to retrieve more details using ajax jQuery.
我有一个基于从MySQL数据库检索的数据的搜索结果。并根据检索到的数据,我嵌入并回显了div和标签,以了解哪些被点击,以便我可以使用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'] . '" />';
}
}
?>
However, the <a>
will have multiple rows been echoed. I need to retrieve the <a>
that is clicked and the value that it is stored in that particular <a>
element. I can't be using id in <a>
because I think it would be tedious. I was thinking to use class so that in javascript I can use document.getElementsByClassName but I know such function in IE has errors.
但是,将有多行被回显。我需要检索单击的以及它存储在该特定元素中的值。我不能在中使用id,因为我觉得它会很乏味。我正在考虑使用类,以便在javascript中我可以使用document.getElementsByClassName,但我知道IE中的此类函数有错误。
Any recommendations?
有什么建议?
2 个解决方案
#1
1
please check jQuery class selector
请检查jQuery类选择器
http://api.jquery.com/class-selector/
http://api.jquery.com/class-selector/
更多相关文章
- 使用PHP和MySQL开发“测试”Web应用程序的数据库设计
- 数据库布局更新是否仍在Magento中使用?
- mysqli类使用预处理语句不返回任何数据
- 使用/发送POST数据时的libcurl C问题(不是c++)
- PHP:在类中使用数据库
- 纯真ip数据库查询的php实现(补充分组查询)
- 添加到数据库后,保持在同一页面而不刷新它
- PHP 导出 万级别数据 时间测试
- 数据库是存储我的Web应用程序数据的最佳选择吗?