在测试我的功能在不同浏览器中的兼容性时,我发现了一个我在 IE 中不知道的行为。
当单词包含字符“&”时,它们看起来会被截断。
javascript 函数从服务器 (c#) 获取一个 json 对象并动态构建一个列表。如果对象的描述是“Test & Test”,那么当 Chrome 和 Firefox 按预期显示描述时,IE 会显示“Test”。
我找到的唯一解决方案是按 F12 并强制“文档模式”为“IE9 标准”。
我尝试了不同的文档类型,与不同的内容值一起使用,我已经包含了 javascript ie9.js 文件(使 MSIE 表现得像一个符合标准的浏览器的文件),将对象的描述包装在 div、span、p 或任何html中可用的一种标签,到目前为止还没有结果。
这是构建列表的 javascript 函数:
$.each(data, function (ind, c) {
if ($container.find('option:contains("' + c.Description + '")').length > 0) {
var name = c.Description;
var $div = $('<div style="margin:0px;padding:0px;width:80%;float:left;" />').html(name).attr({ 'id': c._id });
var $o = $('<li />').html($div).css({ 'margin': 0, 'padding': 0, 'width': '100%', 'font-size': '1em' })
.addClass((ind % 2 == 0 ? 'odd' : 'even'));
if (!(c.IsDefault)) {
var $actionContainer = $('<div />').css({ 'height': 17, 'width': 17, 'float': 'right' });
var $action = $('<button />').html('Delete')
.css({ 'height': 16, 'width': 16 })
.button({
icons: { primary: 'ui-icon-trash' },
text: false
}).click(function () {
if (confirm("Are you sure you wish to delete this object from the list?")) {
var objectId= $(this).parent().parent().children(':first-child').attr('id');
var server = $('#GroupServer').val();
delete($container, server, objectId, $dialog);
}
});
$action.removeClass('ui-corner-all');
$actionContainer.append($action);
$o.append($actionContainer);
}
$ul.append($o);
}
});
和 json 对象:
{ "_id":1,"Description":"Test & Test", "IsDefault":true }
有没有人见过这种行为?除了我已经尝试过的方式之外,是否有可能以其他方式将 IE 的文档模式强制为 IE9 标准?亲切的问候,
洛朗