Php 未调用Jquery函数
我有一个jquery函数,它调用一个php脚本从我的mysql数据库中获取一些数据,jquery函数调用如下:Php 未调用Jquery函数,php,jquery,Php,Jquery,我有一个jquery函数,它调用一个php脚本从我的mysql数据库中获取一些数据,jquery函数调用如下: $(document).ready(function(){ getTopFiveDeals(); 当它运行时,它会很好地获取数据,构建一些HTML并将其插入到网页中。如下图所示: $('ul.special-list').append("<li><a href='#' class=restaurantItem restaurant= '" + item.
$(document).ready(function(){
getTopFiveDeals();
当它运行时,它会很好地获取数据,构建一些HTML并将其插入到网页中。如下图所示:
$('ul.special-list').append("<li><a href='#' class=restaurantItem restaurant= '" + item.estName + "' adddress='" + item.estAddr + "'><img src= " + item.img_link +
" width='60' height='60' alt='" + item.estName + "'><div class='img-det'><strong class='title'> " + item.title + " </strong><p> " + item.desc_short +
" <br>Expires: " + item.expiry_date + " </p><em class='price'>" + item.price + "</em></div></a><a href='dealDetail.html?id=" + item.id +
"' class='det-link'>Detail</a>");
任何帮助和/或建议都将不胜感激
非常感谢您需要为dynanic元素指定事件处理程序,并防止在锚上执行默认操作,以避免滚动到顶部或跟随href
$('ul.special-list').on('click', 'a.restaurantItem', function(event) {
event.preventDefault();
alert('Hello');
});
$a.restaurantItem只叫一次。它不寻找新元素。您需要使用.on的事件委派语法来匹配这些动态创建的元素:
$('ul.special-list').on('click', 'a.restaurantItem', function(e) {
e.preventDefault(); // To stop the link from redirecting the browser
});
用。这边走
你可以在.append项后链接它,它会很好地工作。这很有效,非常感谢你的快速响应,我忘记在我的问题代码中添加even.preventDefault
$('ul.special-list').on('click', 'a.restaurantItem', function(e) {
e.preventDefault(); // To stop the link from redirecting the browser
});
$(document).on('click',"a.restaurantItem",function (event){
event.preventDefault();
alert('Hello');
});