var $ = function (id){return document.getElementById(id);}
window.onload=function(){
$("num").onfocus=function(){
$("show").style.display="block";
}
未捕获的类型错误:未定义不是函数
但是当我将 $("num") 更改为 $("#num") 它可以工作,为什么?
var $ = function (id){return document.getElementById(id);}
window.onload=function(){
$("num").onfocus=function(){
$("show").style.display="block";
}
未捕获的类型错误:未定义不是函数
但是当我将 $("num") 更改为 $("#num") 它可以工作,为什么?
You must have jQuery loaded on your page, and you define $ as a local variable, so during the onload the $ variable take it's old signification which is jQuery. And jQuery uses the same selectors as CSS.
You can solve your problem by disabling jQuery if you don't need it, or setting it in compatibility mode, or setting your $ variable as global variable.
如果您的代码有效
a) 没有加载 jQuery
b)添加缺少的大括号
var $ = function (id){return document.getElementById(id);}
window.onload=function(){
$("num").onfocus=function(){
$("show").style.display="block";
}
}