如何取得一个对象的类型?例如,
var w=window.open("...");
alert(getobjecttype(w));function getobjecttype(obj){
return "window"; //如何得知w 是 window 还是 document 还是 div 还是 input
}
var w=window.open("...");
alert(getobjecttype(w));function getobjecttype(obj){
return "window"; //如何得知w 是 window 还是 document 还是 div 还是 input
}
解决方案 »
- js 地图 设计
- 请教一个JS中正则表达式问题
- player_proxy
- 有人研究JavaScriptMvc 这款框架么?????
- 请教一个判断日期是否合法的javascript
- 如何控制同一个页面下两个区域滚动
- innerHTML JS如何调JS代码.
- 如何实现一个文本域中只允许输入大写,或者可以自动把所有输入的自动以大写形式显示?
- 关于onload
- iframe下有个frameset,frameset中的frame如何引用iframe中的js脚本,如jquery,easyui?
- 求教MainBox.style.left怎么就是取不到呢?
- javascript 如何获得图片上某指定区域的颜色值
<head>
<script type="text/javascript">
function showType(obj){
alert(obj.tagName);
}
window.onload=function(){
showType(document.getElementById("A"));
showType(document.body);
showType(document.getElementById("Text1"));
}
</script>
</head>
<body>
<span id="A"></span>
<input id="Text1" type="text" />
</body>
</html>
以上4个属于不同范畴的层次
window document是实例化的对象
div input 根据lz上下文是指某种类型
<script type="text/javascript">
function showType(obj){
if(obj === window){alert('window');return;}
if(obj === document){alert('document');return;}
alert(obj.tagName);
}
window.onload=function(){
showType(window);
showType(document);
showType(document.body);
showType(document.getElementById("theforever_csdn"));
}
</script>
<div id="theforever_csdn">div</div>
但是,我想要一个通用的解决办法, 就是如何判断传入的object实例化前的原型