<html>
<body>
<script>
function Box()
{
this.Width = 100;
this.Height = 80;
this.Multiply = function()
{
alert(this.Width * this.Height);
}
this.Display = function ()
{
//document.write("<input type='button' onclick='this.Multiply()' value='Click'>");
var thisRef = this;
var btn = document.createElement("INPUT");
btn.type="button";
btn.value="Click";
btn.attachEvent("onclick",function(){thisRef.Multiply();});
document.body.appendChild(btn);
}
}
/* ****** */
var obj = new Box();
obj.Display();</script></body >
</html>
<body>
<script>
function Box()
{
this.Width = 100;
this.Height = 80;
this.Multiply = function()
{
alert(this.Width * this.Height);
}
this.Display = function ()
{
//document.write("<input type='button' onclick='this.Multiply()' value='Click'>");
var thisRef = this;
var btn = document.createElement("INPUT");
btn.type="button";
btn.value="Click";
btn.attachEvent("onclick",function(){thisRef.Multiply();});
document.body.appendChild(btn);
}
}
/* ****** */
var obj = new Box();
obj.Display();</script></body >
</html>
解决方案 »
- javascript中有什么方法可以让页面显示像DIV一样
- 谁帮我解释下代码,一句一句麻烦请说清楚
- 该效果用javascript如何实现?菜鸟求救
- 测试表单项提交的值?
- 求助!!AJAX 如何把document转换为流形式传给JAVA的Servlet
- window.open弹出窗口的标题栏文字如何更改?
- 大侠:可输入的下拉列表框怎么实现
- 请教:如何通过javascript把word嵌入到一个文本框中?
- 分享:JavaScript实现在线编辑表格
- 数组这样写对吗?
- 关于Date对象,只有一句语句,还是说有错!马上给分!
- 一个注册页面 我在输入错误格式的email时 会有js校验 客户端如何才能强制禁止js校验或绕过eamil格式校验
<body>
<script>
function Box(instance)
{
this.Width = 100;
this.Height = 80;
this.instance = new String(instance);
this.Multiply = function()
{
alert(this.Width * this.Height);
}
this.Display = function ()
{
if(window[instance] != this){
throw new Error(-1,"对不起,创建对象时请把对象名称当字符串传进来.");
}
document.write("<input type='button' onclick='" + this.instance + ".Multiply()' value='Click'>");
}
}/* ****** */
var obj = new Box("obj");
obj.Display();
</script></body >
</html>