我在Internet Explorer上的角度应用程序有问题.它运行无处不在(Chrome,Mozilla,Edge),但在IE上.
我已经在Developer Explorer中分析了错误,并返回错误发生在以下行:
myDataSet[index - 1].data = Array.from(tmp);
这是我得到的以下错误消息:
Object does not support property or method from at Anonymous function....(etc.)
我在那里做的是我有一个包含以下数据的Set()命名tmp:
之后我只是从这里创建一个简单的数组对象Set.
我怎么解决这个问题?
编辑
根据建议我已将以下代码添加到我的应用程序:
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === …Run Code Online (Sandbox Code Playgroud) 我正在为我的网站创建一个函数,我在其中设置了一个数据属性,其中包含该元素的第n个子编号.
我的HTML标记:
<html>
<body>
<section class="hardware">some text, nth-child is one</section>
<section class="hardware">some text, nth-child is two</section>
<section class="hardware">some text, nth-child is three</section>
<section class="hardware">some text, nth-child is four</section>
<section class="hardware">some text, nth-child is five</section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
到目前为止我的JavaScript:
var selector = document.getElementsByClassName('hardware');
for(var i = 0; i <= selector.length; i++) {
var index = selector[i] //get the nth-child number here
selector[i].dataset.number = index;
}
Run Code Online (Sandbox Code Playgroud)
如何使用纯JavaScript(而不是jQuery)获取元素的第n个子编号,这在JavaScript中是否可行?