Firefoxでは、このセクションは決してtrueを返すようなことはありません。しかし、それは、ユーザが機能をE1Rating IDを入力ボックスに1から5まで番号を入力する場合はtrueを返すことで、コードが下に入れ子に走る起こっどうあるべきかをGoogle Chromeのなぜこの機能はGoogle Chromeでは機能していますが、Firefoxでは機能していませんか?
if(restrictCharacters(this, event, digitsOnly)==true)
に完璧に適しています。しかし、Firefoxでは、参加者が番号を入力しても何も起こりません。
Firefoxで機能しない部分にコードを削除しました。どのように使用されているかを見ることができます。
document.getElementById("E1TimeStart").value = startTime;
$('#E1Rating').keyup(function() {
if(restrictCharacters(this, event, digitsOnly)==true){
clearTimeout(mytimeout);
var rateTime = new Date().getTime();
$('#E1Rate').hide();
document.getElementById("E1TimeEnd").value = rateTime;
PrepareBox2();
}
else{
//Do nothing and wait for the timeout
}
});
};
これはrestrictCharacters関数です。私は再びそれがクロームで動作するので、それが動作することを知っている。 if == true関数の外で使用すると、この関数もFirefoxで動作します。検索や試しからの私の疑惑は、(this、event、digitsOnly)のイベント参照であるかもしれないということです。しかし、それが事実なら、具体的には何ですか?
/* Purpose: Code will restrict false until it detects the numbers 1 through 5 */
/* Code Source: originally from qodo.co.uk */
// create as many regular expressions here as you need:
var digitsOnly = /[1-5]/g;
function restrictCharacters(myfield, e, restrictionType) {
if (!e) var e = window.event
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
// if they pressed esc... remove focus from field...
if (code==27) { this.blur(); return false; }
// ignore if they are press other keys
// strange because code: 39 is the down key AND ' key...
// and DEL also equals .
if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
if (character.match(restrictionType)) {
return true;
} else {
return false;
}
}
}
ありがとうございます!これらのブラウザの違いについてはどこで知ることができますか? ChromeとFirefoxのJavaScriptイベントの違いを検索してみましたが、あなたが教えてくれたものが見つかりませんでした。 – OneBigNewbie
Firefoxと他のほとんどのブラウザでは、「mdn event」 - > [Mozilla Developer Network> DOM> Event](https://developer.mozilla.org/en/DOM/)のように、イベント)。 IEの場合、私は "msdn javascript event"のためのgoogled、[このページ](http://msdn.microsoft.com/en-us/library/ms535863%28v=vs.85%29.aspx)を手に入れました。 –