javascript button按钮把选中的checkbox用文本框输出
<SCRIPTlanguage="JavaScript">functionadd(target){varstr=document.getElementById(targe...
<SCRIPT language="JavaScript">
function add(target){
var str=document.getElementById(target).value;
var str1=str.value.split(";");
for(i = 0; i < 2; i++){
if($(tablebox.TableWrapper.Table1.che[i].checked ==true){
for(j=0; j < 2; i++){
if(str1[j] == tablebox.TableWrapper.Table1.che[i].value){
break;
}else{
str1=str1+";"+tablebox.TableWrapper.Table1.che[i].value;
}
}
}
}
}
</SCRIPT>
<div id="button3">
<button type="button" style="margin-left:450px;margin-top:15px" class="littleButton1" onclick="search('text')">search</button>
</div>
<div id="tablebox">
<div id="TableWrapper" style="width:580px;height:340px;">
<table id="Table1" style="width: 100%; margin-left:30px; border-collapse: collapse;" border="1px">
<tr>
<th scope="col"></th>
<th scope="col">a</th>
<th scope="col" id="col1">a</th>
<th scope="col">a</th>
<th scope="col">a</th>
</tr>
<tr>
<td><input type="checkbox" name="che0" value="aaa"/></td>
<td>aa</td>
</tr>
<tr>
<td><input type="checkbox" name="che1" value="bbb" /></td>
<td>bb</td>
</tr>
</table>
</div>
</div>
<div id="button5">
<button type="button" style="margin-left:450px;" class="littleButton9" onclick="add('text1')">追加</button>
</div>
<input type="text" maxlength="20" style="margin-left: 80px;width: 480px;" id="text1"></input>
例:checkbox选中第一个,按下追加按钮,文本框就会出现:aa。(相同checkbox,多次按追加按钮,内容不变) 展开
function add(target){
var str=document.getElementById(target).value;
var str1=str.value.split(";");
for(i = 0; i < 2; i++){
if($(tablebox.TableWrapper.Table1.che[i].checked ==true){
for(j=0; j < 2; i++){
if(str1[j] == tablebox.TableWrapper.Table1.che[i].value){
break;
}else{
str1=str1+";"+tablebox.TableWrapper.Table1.che[i].value;
}
}
}
}
}
</SCRIPT>
<div id="button3">
<button type="button" style="margin-left:450px;margin-top:15px" class="littleButton1" onclick="search('text')">search</button>
</div>
<div id="tablebox">
<div id="TableWrapper" style="width:580px;height:340px;">
<table id="Table1" style="width: 100%; margin-left:30px; border-collapse: collapse;" border="1px">
<tr>
<th scope="col"></th>
<th scope="col">a</th>
<th scope="col" id="col1">a</th>
<th scope="col">a</th>
<th scope="col">a</th>
</tr>
<tr>
<td><input type="checkbox" name="che0" value="aaa"/></td>
<td>aa</td>
</tr>
<tr>
<td><input type="checkbox" name="che1" value="bbb" /></td>
<td>bb</td>
</tr>
</table>
</div>
</div>
<div id="button5">
<button type="button" style="margin-left:450px;" class="littleButton9" onclick="add('text1')">追加</button>
</div>
<input type="text" maxlength="20" style="margin-left: 80px;width: 480px;" id="text1"></input>
例:checkbox选中第一个,按下追加按钮,文本框就会出现:aa。(相同checkbox,多次按追加按钮,内容不变) 展开
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>cainiao</title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function ()
{
PageModel.produceTrs ();
败档}
var PageModel =
{
index : 0,
page : 14,
end : 1,
all : 20,
col : 5,
bottomLine : 2,
word : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
produceTrs : function ()
{
var table = document.getElementById ("Table1");
var info = document.getElementById ("info");
var wp = this.word.split ('');
for ( var i = this.page * this.index; i < this.page * (this.index + 1); i++)
{
var tr = table.insertRow (table.rows.length - this.bottomLine);
for ( var j = 0; j < this.col; j++)
碧粗 {
var td = tr.insertCell (tr.cells.length);
if (j == 0)
{
var ck = document.createElement ("input");
ck.type = "checkbox";
ck.name = "che" + i;
ck.value = wp[i] ? wp[i] : "";
td.appendChild (ck);
}
else
{
for ( var k = 0; k <= j; k++)
{
td.innerHTML += (wp[i] ? wp[i] : "");
}
}
}
}
info.innerText = (this.index + 1) + " / " + (this.all);
},
removeTrs : function ()
{
var table = document.getElementById ("Table1");
var len = table.rows.length;
while (len > this.bottomLine + 1)
{
table.deleteRow (1);
len = table.rows.length;
}
},
toPage : function (dir)
{
var table = document.getElementById ("Table1");
var info = document.getElementById ("info");
if (dir == -1)
{
this.index = this.index == 0 ? 0 : --this.index;
}
else if (dir == 1)
{
this.index = this.index == this.all ? this.all : ++this.index;
}
else if (dir == -2)
{
this.index = 0;
}
else if (dir = 2)
{
this.index = this.all - 1;
}
info.innerText = (this.index + 1) + " / " + (this.all);
察慧乱this.removeTrs ();
this.produceTrs ();
}
};
var appendWord = function ()
{
var text1 = document.getElementById ('text1');
var cks = document.getElementsByTagName ("input");
var temp = ";" + text1.value + ";";
for ( var i = 0; i < cks.length; i++)
{
var ck = cks[i];
if (ck.type == 'checkbox' && ck.checked)
{
var text = ck.parentElement.parentElement.cells[1].innerText;
if (temp.indexOf (";" + text + ";") == -1)
{
temp += text + ";";
}
text1.value = temp.replace (/;;/g, ';').replace (/^;|;$/g, '');
temp = ";" + text1.value + ";";
}
if (ck.type == 'checkbox' && !ck.checked)
{
var text = ck.parentElement.parentElement.cells[1].innerText;
var str = ";" + text + ";";
var reg = new RegExp (str, "g");
if (reg.test (str))
{
temp = temp.replace (reg, ";");
}
text1.value = temp;
}
}
text1.value = temp.replace (/;;/g, ';').replace (/^;|;$/g, '');
};
</script>
</head>
<body style="text-align: center;">
<div id="tablebox">
<div id="TableWrapper" style="text-align: center; height: 340px;">
<table id="Table1"
style="width: 60%; margin: 0 auto; border-collapse: collapse;"
border="1px">
<tr>
<th scope="col"></th>
<th scope="col">a</th>
<th scope="col" id="col1">a</th>
<th scope="col">a</th>
<th scope="col">a</th>
</tr>
<tr>
<td colspan="5"><input type="button" value="<"
onclick="PageModel.toPage(-2);" /> <input type="button" value="前"
onclick="PageModel.toPage(-1);" /> <span id="info"></span> <input
type="button" value="后" onclick="PageModel.toPage(1);" /> <input
type="button" value=">" onclick="PageModel.toPage(2);" />
</td>
</tr>
<tr>
<td colspan="4"><input type="text" maxlength="20"
style="width: 80%" id="text1"></input>
</td>
<td colspan="1"><button type="button" class="littleButton9"
onclick="appendWord();">追加</button></td>
</tr>
</table>
</div>
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询