gpt4 book ai didi

javascript - 在 IE7/IE8 中获取尾随逗号(在 JavaScript 中)

转载 作者:行者123 更新时间:2023-11-28 15:54:09 26 4
gpt4 key购买 nike

您可以在这里找到很多关于尾随逗号的信息: Are trailing commas in arrays and objects part of the spec?

这是关于“就在那里”的逗号。

[
{ title: "..", display: function() { return ".."; } },
{ title: "..", display: function() { return ".."; } },
{ title: "..", display: function() { return ".."; } }, // <--right there
]

我现在的问题是,第三方工具生成此列表时带有逗号,我无法访问该工具的源代码。我

<body>
my stuff
<!-- the folloging div with the javascript comes from the 3rd party -->
<div class="item"><script type="text/javascript">
$(document).ready(function() {


$.supersized({

// Functionality
slide_interval : 8000, // Length between transitions
transition : 1, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed : 400, // Speed of transition
fit_always : 0, //Prevents the image from being cropped by locking it at 100% width.
min_width : 600, //min-width of images
random : 0, //random img
vertical_center : 1, //vertical alignment

// Components
slide_links : 'false', // Individual links for each slide (Options: false, 'number', 'name', 'blank')
slides : [ // Slideshow Images

{image : 'image1.jpg', otherstuff: 'blah', moreotherstuff: 'lorem'},

{image : 'image2.jpg', otherstuff: 'blub', moreotherstuff: 'ipsum'},


]
});
});
</script></div>

现在我问我有没有办法让它在 IE7/IE8 中工作。

我现在看到的唯一方法(因为我无法编辑第 3 方并且无法在服务器上访问它)是:- 给出一个没有那个 div 的特殊输出- 通过ajax请求正常端- 解析所有内容,获取此 div,删除最后一个逗号并执行 javascript

这确实不是我想要的方式。还有其他方法可以解决这个问题吗?

最佳答案

IE7/IE8 将报告 1 个元素更大的数组长度,除非您 trim 这些数组。

如果您知道所有接受来自第三方的数据的 JS 方法,您可以为它们编写包装器。例如:

var removeEmpty = function(array){
var i, result = [];

for (i = 0; i < array.length; ++i){
if ( typeof array[i] != 'undefined' ){
result.push(array[i]);
}
}

return result;
};

$.supersized = (function() {
var origMethod = $.supersized;

return function(config) {
config.slides = removeEmpty(config.slides); // get rid of undefined data in array
return origMethod.call(this, config); // call original method
};
}());

关于javascript - 在 IE7/IE8 中获取尾随逗号(在 JavaScript 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19450114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com