eleLayer.attachEvent ('onmouseover', YouFunctionName);
解决方案 »
- json object 转 stirng 的问题
- ext grid 的根据前一项 后一项相应的值发生改变咋写?
- 关于js 打印出客户端浏览器信息的一些疑问。
- 遍历控件对象捆绑事件~参数传值错误~高手都来解释一下
- 看看这个函数 为什么在 IE 下无法用 function getEvent()
- 如何用js实现慢慢窗帘式显示一个框框或是一个层吧.
- 各位帮我看看这窗口是咋回事呢?
- 给客户做的网站,有一点在客户的机器上不行,请大家帮忙分析一下
- 一个关于 setTimeOut 的问题,,
- input type="checkbox" 的只读属性怎么设置?readonly不行
- 关于拷屏键的屏蔽~~~(PrintScreen)坚决加出100分,只要你来,就给分
- 百思不得其解,为什么得到“null”,在线等待中...
老说类型不匹配,why?
MDown是一个鼠标拖动函数
eleLayer.attachEvent("onmousedown",MDown(this.cra))
提示id为空或不是对象
eleLayer.attachEvent("onmousedown",MDown(this))
提示类型不匹配
eleLayer.onmousedown=randomMoveResultLayer;//给层添加一个处理句柄
function randomMoveResultLayer(){
//------
}
或者
eleLayer.onmousedown=function {------};//给层添加一个处理句柄如果处理函数有多个参数,如下
eleLayer.onmousedown=function { fun1(2,3,4); };//给层添加一个处理句柄
function fun1(v1,v2,v3){
alert(v1+v2+v3);
}
大花猫:
attach不行吗?
<SCRIPT LANGUAGE="JScript">
attachEvent ('onmouseover', Hilite);
attachEvent ('onmouseout', Restore);
function cleanup()
{
detachEvent ('onmouseover', Hilite);
detachEvent ('onmouseout', Restore);
}
function Hilite()
{
if (event.srcElement == element)
{
normalColor = style.color;
runtimeStyle.color = "red";
runtimeStyle.cursor = "hand";
}
}
function Restore()
{
if (event.srcElement == element)
{
runtimeStyle.color = normalColor;
runtimeStyle.cursor = "";
}
}
提示“尚未实现”
该咋办?
应该可以添加事件的,只是麻烦点,偶不懂该是哪个属性请高人指点
<HEAD>
<title>title</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="JavaScript">
<!--
function MDown()
{
alert("成功");
}
var i=0;
function create()
{
var cra=i+1;
var cleft = 530*Math.random();
var ctop =280*Math.random();
var eleInput = document.createElement("INPUT");
eleInput.setAttribute("id",cra);
//eleInput.attachEvent("onmousedown",MDown(this));//添加事件
//eleInput.onmousedown = MDown();
eleInput.style.setAttribute("position","absolute");
eleInput.style.setAttribute("height","20");
eleInput.style.setAttribute("width","70");
eleInput.style.top = ctop;
eleInput.style.left = cleft;
document.body.appendChild(eleInput);
i++;
return false;
}
-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 101; LEFT: 328px; WIDTH: 56px; POSITION: absolute; TOP: 432px; HEIGHT: 24px"
onclick="create()" type="button" value="Create">
</form>
</body>
</HTML>
<HTML>
<HEAD>
<title>title</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="JavaScript">
<!--
function MDown()
{
alert("成功");
}
var i=0;
function create()
{
var cra=i+1;
var cleft = 530*Math.random();
var ctop =280*Math.random(); var eleInput = document.createElement("INPUT");
eleInput.setAttribute("id",cra);
//eleInput.attachEvent("onmousedown",MDown(this));//添加事件
//eleInput.onmousedown = MDown();
eleInput.style.setAttribute("position","absolute"); eleInput.style.setAttribute("height","20");
eleInput.style.setAttribute("width","70");
eleInput.style.top = ctop;
eleInput.style.left = cleft;
document.body.appendChild(eleInput);
i++;
return false;
}
-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 101; LEFT: 328px; WIDTH: 56px; POSITION: absolute; TOP: 432px; HEIGHT: 24px" onclick="create()" type="button value="Create">
</form>
</body>
</HTML>
eleLayer.onmousedown = function { MDown(cra);}fucntion MDown(cra){
//------------------
}
{
alert("成功");
}
eleLayer.onmousedown = function { MDown(); }
为啥会提示缺少'('
请指点
应该是
function MDown()
{
alert("成功");
}
eleLayer.onmousedown = function() { MDown(); }
<HTML>
<HEAD>
<title>title</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="JavaScript">
<!--
function MDown()
{
alert("成功");
}
var i=0;
function create()
{
var cra=i+1;
var cleft = 530*Math.random();
var ctop =280*Math.random(); var eleInput = document.createElement("INPUT");
eleInput.setAttribute("id",cra);
//eleInput.attachEvent("onmousedown",MDown(this));//添加事件
eleInput.onmousedown = function () {MDown();}
eleInput.style.setAttribute("position","absolute"); eleInput.style.setAttribute("height","20");
eleInput.style.setAttribute("width","70");
eleInput.style.top = ctop;
eleInput.style.left = cleft;
document.body.appendChild(eleInput);
i++;
return false;
}
-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 101; LEFT: 328px; WIDTH: 56px; POSITION: absolute; TOP: 432px; HEIGHT: 24px" onclick="create()" type="button value="Create">
<INPUT style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 432px" onclick="alert( document.body.outerHTML )" type="button" value="HTML">
</form>
</body>
</HTML>
为啥点HTML按纽看不到添加的INPUT的onmousedown事件呢?
?????少了一个“"”,双银号。
<HTML>
<HEAD>
<title>title</title>
<script language="javascript">
var i=0;
function MDown()
{
alert("成功");
} function create()
{
var cra=i+1;
var cleft = 530;
var ctop =280;
var eleInput = document.createElement("INPUT");
eleInput.setAttribute("id",cra);
//eleInput.attachEvent("onmousedown",MDown(this));//添加事件
eleInput.onmousedown = function () {MDown();}
eleInput.style.setAttribute("position","absolute");
eleInput.style.setAttribute("height","20");
eleInput.style.setAttribute("width","70");
eleInput.style.top = ctop;
eleInput.style.left = cleft;
document.body.appendChild(eleInput);
i++;
}
</script>
</HEAD>
<body >
<form id="Form1" method="post" >
<INPUT type="button" value="Create" onclick="create()" >
<INPUT style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 432px" onclick="alert( document.body.outerHTML )" type="button" value="HTML">
</form>
</body>
</HTML>
应为
attachEvent("onmousedown",MDown)attachEvent第二个参数是函数名称,不可以加参数和括号的。这应该是一个缺陷吧。
在HTML代码中可以用 <span onmousedown="MDown(this)">span title</span>
但在JS里却不行,不知道为什么
<HTML>
<HEAD>
<title>title</title>
<script language="javascript">
var i=0;
function MDown()
{
alert("成功");
} function create()
{
var cra=i+1;
var cleft = 530;
var ctop =280;
var eleInput = document.createElement("INPUT");
eleInput.setAttribute("id",cra);
eleInput.attachEvent("onmousedown",MDown);//添加事件
//eleInput.onmousedown = function () {MDown();}
eleInput.style.setAttribute("position","absolute");
eleInput.style.setAttribute("height","20");
eleInput.style.setAttribute("width","70");
eleInput.style.top = ctop;
eleInput.style.left = cleft;
document.body.appendChild(eleInput);
i++;
}
</script>
</HEAD>
<body >
<form id="Form1" method="post" >
<INPUT type="button" value="Create" onclick="create()" >
<INPUT style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 432px" onclick="alert( document.body.outerHTML )" type="button" value="HTML">
</form>
</body>
</HTML>