我的 html 页面中有以下工作 JavaScript 代码。
<SCRIPT language='Javascript'>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</SCRIPT>
但我听说 language="javascript"已被弃用,因此尝试使用与下面相同的代码更改 language="text/javascript"但不起作用。
<SCRIPT language="text/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</SCRIPT>
有人可以告诉我如何使代码在 language="text/javascript"模式下工作吗?
最佳答案
更好(因为它更短且更容易阅读):
<script>
//Some script
</script>
来自spec ,强调:
The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".
关于javascript代码在语言="text/javascript"时不起作用,但在语言='Javascript'时起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20981604/