2015-01-14 63 views
0

我使用的是动态图像。这意味着图像标签内部我使用动态链接src和动态文本alt.For src它工作正常,但在alt中,我不是获取文本。这里是我的img标签的例子。Alt标签不适用于动态图像标签

<img style="top: 0px !important;" data-frame="<%=thumb%>" src="<%=image%>" alt="<%= advertiseObj.getAdTitle() %>" /> 
+0

看起来这类似的问题,http://stackoverflow.com/questions/4248823/how-to-insert-alt-tags-dynamically-in-jsp,只要看看它 –

+0

,而是发生了什么?为什么你仍然在使用脚本,虽然他们不应该再使用多年了? –

+0

JB,我明白你对scriptlet的含义,但说实话,对于他在做的事情,唯一的选择将是一个servlet,因为这是微不足道的,或者jstl,它被授予,不被弃用,但是就像明智的代码一样。 ** OP:您是否确定您的广告标题没有返回空字符串或null?查看页面源代码并向我们展示servlet容器实际输出的内容** – zack6849

回答

0

现在解决了这个问题,因为javascript效果没有得到alt。

我正在使用img作为图库框架。所以我正在为jquery设置该图库的框架。所以这里是我的旧代码。

(function ($) { 
// custom image object 
var gvImage = function (img) { 

    this.src = { 
     panel: img.attr('src'), 
     frame: img.data('frame') || img.attr('src') 
    }; 
    this.scale = { 
     panel: null, 
     frame: null 
    }; 
    this.height = 0; 
    this.width = 0; 
    this.attrs = { 
     title: img.attr('title') || img.attr('alt'), 
     description: img.data('description') 
    }; 
    this.href = null; 
    this.dom_obj = null; 

    return this; 
}, 

我也为alt添加了一些东西,它只是一个打击和trail.But它为我工作。这里是我的新代码。

(function ($) { 
// custom image object 
var gvImage = function (img) { 

    this.src = { 
     panel: img.attr('src'), 
     frame: img.data('frame') || img.attr('src') 
    }; 
    this.alt = { 
      panel: img.attr('alt'), 
      frame: img.attr('alt') 
     }; 
    this.scale = { 
     panel: null, 
     frame: null 
    }; 
    this.height = 0; 
    this.width = 0; 
    this.attrs = { 
     title: img.attr('title') || img.attr('alt'), 
     description: img.data('description') 
    }; 
    this.href = null; 
    this.dom_obj = null; 

    return this; 
},