<div class="headerimage"><img src="images/events.png"/></div>
<?php
foreach (LoadEvent() as $value){
echo '<div class="dynamicsidemenu eventback">';
echo "<a class=\"event\"id=" .$value['eventsearchresultid']. " href='#' value=" .$value['eventsearchresultid']. ">".$value['eventsearchresultwhat']."</a>";
echo "<br/>\n";
echo $value['eventsearchresultwhen'];
echo "<br/>\n";
echo $value['eventsearchresultwhere'];
echo '</div>';
}
?>
$(document).ready(function(){
var id = $(".event").attr("value");
var a = document.getElementById(id);
a.addEventListener("click", function(event){
event.preventDefault();
alert(this.getAttribute(id));
//var $id = this.getAttribute("value");
$('#leftcolumncontainer').load('pages/upcomingeventsmenu.php');
$('#middlecolumncontainer').load('pages/upcomingeventscontent.php?id=' + id );
});
});
我这里有一个代码o来自数据库的最后5个条目每个链接转到每个事件的详细信息页面我能够使第一个链接转到详细页面,但第二个链接没有触发这里的错误。 任何帮助表示赞赏
答案 0 :(得分:1)
您应该在id
事件处理程序中定义click
,试试这个:
$(document).ready(function(){
$(".event").on('click', function (event) {
event.preventDefault();
var id = $(this).attr('id');
$('#leftcolumncontainer').load('pages/upcomingeventsmenu.php');
$('#middlecolumncontainer').load('pages/upcomingeventscontent.php?id=' + id);
});
});
答案 1 :(得分:0)
更改锚点标记行,如下所示:
echo "<a class=\"event\" id=\"" .$value['eventsearchresultid']."\" href=\"#\" value=\"".$value['eventsearchresultid']."\">".$value['eventsearchresultwhat']."</a>";