这可能是太多的信息,但你去吧......用户输入一个 url 并且 url 通过 ajax 发送到后端以确认它存在。如果是,它会返回 url 和 contentType(text/html、image/jpeg...ect)。下面的代码是 ajax 成功回调。
var template =
"<span class='urlFile'>"+data.contentType+'</span>'+
"<span class='urlPath' title="+data.url+'>'+data.url+'</span>';
$(template).prependTo(fieldWrapper);
问题是生成的 html 呈现部分乱序。下面是 Firebug (Chrome) 的输出补充。请注意 data.url ( http://api.jquery.com/appendto/ ) 没有包含在 span.urlPath 中。
<span class="urlFile">html</span>
<span class="urlPath" title="http://api.jquery.com/appendto"></span>
http://api.jquery.com/appendto/
此外,当我添加一个时,alert(template)
我得到:
<span class='urlFile'>html</span>
<span class='urlPath' title=http://api.jquery.com/prependto/>http://api.jquery.com/prependto/</span>
...哪个是对的。我相信这个问题与渲染尾随的浏览器有关/
;但是,除了删除斜线之外,我不确定如何修复它。
仅供参考:删除尾部斜杠似乎可以解决问题,即:
var url = data.url.replace(/\/$/,'');
...但是真的需要吗?听起来这是一个坏主意: