0

I am trying to create a div, that is being appended to another div. Seems to be working but, the ruby code is not recognized and the image tag does not load:

function add_event(event)
{
    var div=document.createElement('div');
    div.innerHTML='<%= image_tag("events_pics/band.png", :class=> "event_pic_small") %><h6 class="event_info">Event_1: Frame: 974</h6><a class="btn btn-mini btn-danger pull-right " href="#"><i class="icon-remove"></i></a>';
    div.className='user_event my_background';
    $("#event_list").append(div);

}

Plus I would like to assign a function on the <i class="icon-remove"></i> so, is there a more elegant way to create that div?

4

1 回答 1

2

您意识到 Javascript 在服务器代码(Rails)产生响应之后执行。

这就是无法识别 image_tag 的原因。

基本上,您不能在 javascirpt 文件中使用 <%= xxx %> 因为这些标记被 rails 服务器端识别并在响应发送回浏览器之前进行处理。然后你的javascript代码开始。

于 2012-06-21T15:06:20.827 回答