简体   繁体   English

jQuery创建的img标签和ASP.Net创建的img标签的显示差异

[英]Difference in display for jQuery created img tag and ASP.Net created img tag

My web page has two ways of displaying a particular content. 我的网页有两种显示特定内容的方式。 1. When the page is loaded, the items ( images with anchor tag) are generated using ASP Repeater. 1.加载页面后,将使用ASP Repeater生成项目(带有定位标记的图像)。 2. When user perform some Ajax action, the images are returned as JSON and I use jQuery for creating the a & img tags. 2.当用户执行某些Ajax操作时,图像将以JSON形式返回,并且我使用jQuery创建了a&img标签。

In both these methods, the anchor tags with images are displayed with width 60px. 在这两种方法中,带有图像的锚标签都以60px的宽度显示。 There is no CSS class applied. 没有应用CSS类。 But strangely the display is not consistent. 但是奇怪的是显示不一致。 Here is the both displays: alt text http://img132.imageshack.us/img132/7528/38297001.gif 这是两种显示方式: 替代文字http://img132.imageshack.us/img132/7528/38297001.gif

I wonder why this difference occur. 我不知道为什么会出现这种差异。 I check this with all browsers ( IE,FF& chrome) and all behave the same. 我在所有浏览器(IE,FF&chrome)中都检查了这一点,它们的行为都一样。 Here is my jQuery code: 这是我的jQuery代码:

$('<a>').attr({ href: '/Detail.aspx?id=' + result.it[i].pid, title: result.it[i].nam })  .html("<img src='" + result.it[i].url + "' title='" + result.it[i].nam + "' alt='" + result.it[i].nam + "' width='60px' />").appendTo("#SummaryDiv");

Any idea why this behaviour occurs? 知道为什么会出现这种现象吗? I also checked the css applied to these elements in chrome and FF.. they seems to have all the same CSS attributes. 我还检查了chrome和FF中应用于这些元素的css。它们似乎都具有相同的CSS属性。

Is the created markup identical? 创建的标记是否相同? Is it valid (x)html? 它是有效的(x)html吗?

Do you have white space between the image tags or anchors created by the repeater? 中继器创建的图像标签或锚之间是否有空白? If yes, remove it. 如果是,请将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM