Number.isIntegerは一部のIEブラウザでは機能しません。私はコントロールのwheather値が整数かどうかを作成しています。Number.isIntegerの代わりに何が使えますか?
var decimalBasePriceKontol = Number.isInteger(BasePrice);
これは私の可変です。
これ以外に、すべてのブラウザでこれを行うために使用できるものはどれですか。
おかげで、
Number.isIntegerは一部のIEブラウザでは機能しません。私はコントロールのwheather値が整数かどうかを作成しています。Number.isIntegerの代わりに何が使えますか?
var decimalBasePriceKontol = Number.isInteger(BasePrice);
これは私の可変です。
これ以外に、すべてのブラウザでこれを行うために使用できるものはどれですか。
おかげで、
あなたはMozilla Polyfillよりも良くなることはありません。これをスクリプトの先頭に追加してください:
Number.isInteger = Number.isInteger || function(value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value;
};
ここでは何をしていますか?
// This line makes sure that the function isInteger exists.
// If it doesn't it creates it
Number.isInteger = Number.isInteger || function(value) {
// This line checks to make sure we're dealing with a number object.
// After all "cat" is not an integer
return typeof value === 'number' &&
// This line makes sure we're not checking Infinity.
// Infinity is a number, and if you round it, then it equals itself.
// which means it would fail our final test.
isFinite(value) &&
// If you round, floor, or ceil an integer, the same value will return.
// if you round, floor, or ceil a float, then it will return an integer.
Math.floor(value) === value;
}
これはドキュメントにあります。 –
なぜ誰かが正しい答えとしてこれを下降させるのかどうかは確かではありませんか? @ChrisGまさにその文書の中で。何を言おうとしているのですか? – Xatenev
私はしませんでしたが、この回答は文書*にあります。その答えは、ドキュメントをスキップし、代わりにここに来ることを奨励します。 –
注:それは、値が数値(整数、浮動小数点、...)である場合にのみ機能します。他のタイプについてもチェックすることができます。
文字列に変換して、.
文字(小数点)があるかどうかを確認できます。
if (!Number.isInteger) { // If Number.isInteger is not defined
Number.isInteger = function (n) {
return n.toString().indexOf(".")==-1;
};
}
https://developer.mozilla.org/en-US/(Number.isIntegerの最初の使用の前にそれを実行する):
またNumber.isIntegerの交換を行うことができますdocs/Web/JavaScript/Reference/Global_Objects/Number/isIntegerは、あなたが '' Number.isInteger = Number.isInteger ||を使うことができるpolyfillを示しています。関数値(値){ 戻り値の型=== '数値' && isFinite(value)&& Math.floor(value)=== value; }; '' ' –
downvote質問は研究努力を示していません。 MDNのドキュメントに記載されているソリューションを除けば、単純なgoogle 'Number.isInteger Internet Explorer'は即座の結果をもたらします。 – Nope
私はpolyfillでこれを修正しました。ありがとう、 –