日期:2014-05-19  浏览次数:20399 次

就是页面上有好多按钮 我要按下按钮后 在文本框里面纪录按下按钮的id ,当然再次按同一个按钮时就是在文本框中去除或增加此按钮id
如题目

------解决方案--------------------
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> Untitled Page </title>
<script language= "javascript " type= "text/javascript ">
var strText= " ";
function clickMe(myid)
{
var strValue = document.getElementById( "Text1 ").value;
if(strText.lastIndexOf(myid+ ', ') <0)
{
strText += myid+ ", ";
strValue = strText.substr(0,strText.length-1);
}
else
{
strText = strText.replace(myid+ ', ', ' ');
strValue = strText;
}
if(strValue.substr(strText.length-1,strText.length)== ", ")
{
strValue = strValue.substr(0,strText.length-1);
}
document.getElementById( "Text1 ").value = strValue;
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
&nbsp;&nbsp;
<input id= "Text1 " type= "text " />
<input id= "Button1 " type= "button " value= "button " onclick= "clickMe(this.id) " />
<input id= "Button2 " type= "button " value= "button " onclick= "clickMe(this.id) "/>
<input id= "Button3 " type= "button " value= "button " onclick= "clickMe(this.id) "/> </div>
</form>
</body>
</html>