Jquery 第二次未追加数据
我想在点击图标时显示数据。数据第一次显示,但第二次不显示。我正在将数据附加到Jquery 第二次未追加数据,jquery,ruby-on-rails,Jquery,Ruby On Rails,我想在点击图标时显示数据。数据第一次显示,但第二次不显示。我正在将数据附加到$('body')元素 my view.js.html.erb是 $(".view-schemes").live('click', function(e) { var schemes_url = "<%= show_schemes_products_path %>"; var p_id = $(this).attr('id'); get_data(schemes_url, { id:
$('body')
元素
my view.js.html.erb是
$(".view-schemes").live('click', function(e) {
var schemes_url = "<%= show_schemes_products_path %>";
var p_id = $(this).attr('id');
get_data(schemes_url, { id: p_id }, function(data) {
$('body').append(data);
},"html");
});
$(“.view schemes”).live('click',函数(e){
var方案_url=“”;
var p_id=$(this.attr('id');
获取数据(schemes\u url,{id:p\u id},函数(data){
$('body')。追加(数据);
},“html”);
});
我第二次得到数据,但数据并没有附加到身体上。是否有任何解决方案或其他编写此查询的方法 尝试使用
id=“added\u div”
在正文中创建新div。
每次单击。查看方案
,都会在追加的div中追加数据。
更改后,您的JS代码将如下所示:
$(".view-schemes").live('click', function(e) {
var schemes_url = "<%= show_schemes_products_path %>";
var p_id = $(this).attr('id');
get_data(schemes_url, { id: p_id }, function(data) {
$('#appended_div').empty();
$('#appended_div').append(data);
},"html");
});
$(“.view schemes”).live('click',函数(e){
var方案_url=“”;
var p_id=$(this.attr('id');
获取数据(schemes\u url,{id:p\u id},函数(data){
$(“#追加_div”).empty();
$('#追加_div')。追加(数据);
},“html”);
});
希望这能解决你的问题。谢谢首先,请使用当前版本的jQuery
$(".view-schemes").live('click', function(e) {
...
可以更改以捕获更灵活的元素
$('body').on('click', '.view-schemes', function(e) {
...
这有助于在加载页面后添加元素。为什么文件名像view.js.html.erb
?每次单击时是否可以alert(data)
?使用哪个版本的jquery。很久以前我就看过.live