87,910
社区成员
发帖
与我相关
我的任务
分享
input.onfocus = funtion(){
msg(this);
}
事件绑定的时候需要指向一个函数,你的那种写法,是把msg函数的返回值给了onfucus事件。<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div>
<div id="basicinfo_div_1" style="float:left;position:relative; width: auto; height: 100%; min-width: 50px; background-color: Gray; ">工程名称:<br/><input type="text" id="projectname_1" /><br/>分项工程名称:<br/><input type="text" id="subname_1"/></div>
<div id="classname_div" style="float:left;position:relative; width: auto; height: auto; min-width: 50px; background-color: green; ">
<div id="classname_div_1" style="float:left;position:relative; width: 100%; height: auto; min-width: 50px; background-color: green; ">
<input type="text" id="st_1" value="1" style=" display:none">分类名称:<br/><input type="text" id="classname_1" onfocus="msg(this)"/>
</div>
<div id="classname_div_button_1" style="float:left;position:relative; width: 100%; height: auto; min-width: 50px; background-color: green; ">
<button type="button" id="add_classname" onclick="addclassname(this)">增加一条</button>
<button type="button" id="reduce_classname" onclick="addclassname(this)">减少一条</button>
</div>
</div>
<div id="step1name_div_1" style="float:left;position:relative; width: auto; height: 100%; min-width: 50px; background-color: red; "></div>
<div id="step2name_div_1" style="float:left;position:relative; width: auto; height: 100%; min-width: 50px; background-color: white; "></div>
</div>
</body>
</html>
<script type="text/javascript">
function addclassname(obj)
{
var cdiv=document.getElementById("classname_div_1");
var st_1=document.getElementById("st_1");
if (obj.id=="add_classname")
{
var input=document.createElement("input");
input.type="text";
input.onfocus=function()
{
alert(this.id);
};
st_1.value=parseInt(st_1.value,10) + 1;
input.id="classname_"+st_1.value;
cdiv.appendChild(input);
}
if (obj.id=="reduce_classname")
{
if(st_1.value==0)
{
return;
}
var input=document.getElementById("classname_"+ st_1.value);
cdiv.removeChild(input);
st_1.value=parseInt(st_1.value,10) -1;
}
}
function msg(obj)
{
alert(obj.id)
}
</script>