我正在做一个程序我需要从excel复制数据并粘贴到浏览器我的程序运行良好当我将excel中的数据粘贴到文本框中时它会拆分表中的所有行但我只想拆分第一列中包含的单元格我不想拆分所有行...
***输入No Of Rows:
<form id='mform' action="EnterData" method='post'>
<table>
<tr>
<td>
<button type="submit" value="Save">Save</button>
</td>
<p style="color: red;">${message2}</p>
</tr>
<tr>
<th>TIMEBlockNo.</th>
<th>TimeInformation</th>
</tr>
</table>
<table id='myform'>
</table>
</form>
</body>
<script type="text/javascript">
var i = 0;
function increment(){
i += 1;
}
function removeElement(parentDiv, childDiv)
{
if (childDiv == parentDiv)
{
alert("The parent div cannot be removed.");
}
else if (document.getElementById(childDiv))
{
var child = document.getElementById(childDiv);
var parent = document.getElementById(parentDiv);
parent.removeChild(child);
}
else
{
alert("Child div has already been removed or does not exist.");
return false;
}
}
function createRow()
{
var j = document.getElementById("numm").value;
var r = document.getElementById("myform");
var mf = document.getElementById("mform");
r.remove();
var r = document.createElement("TABLE");
r.setAttribute("ID", "myform");
mf.appendChild(r);
var n=0;
for(var k=0;k<j;k++)
{
var rr = document.createElement("TR");
r.appendChild(rr);
for(var i=0;i<2;i++)
{
var d = document.createElement("TD");
rr.appendChild(d);
var a = document.createElement("INPUT");
a.setAttribute("type", "text");
a.setAttribute("onkeyup", "formatCells(this.value,'t1')");
a.setAttribute("Name", "t1_" + n);
d.appendChild(a);
n++;
}
}
}
function formatCells(xls,group){
var m =0;
var arr Group = null;
var arrGro = xls.split(" ");
for(var l=0;l<arrGro.length;l++)
{
arrGroup = arrGro[l].split("\t");
for(var i=0;i<arrGroup.length;i++){
document.forms[0].elements[group + "_" + m].value = arrGroup[i];
m++;
}
}
}
</script>
</html>***
答案 0 :(得分:0)
<body>
<style>
input {
width: 80px;
}
table
{
border-collapse: collapse;
width: 100%;
}
th,td{
text-align: left;
padding: 8px;
}
tr:nth-child(even)
{
background-color: #f2f2f2
}
th{
background-color: #4CAF50;
color: white;
}
</style>
Enter No Of Rows: <input name="ss" id = 'numm' type="number" onkeyup="createRow()"><br>
<form id='mform' action="EnterData" method='post'>
<table><tr> <td><button type="submit" value="Save">Save</button></td></tr>
<tr>
<th>TIMEBlockNo.</th>
<th>TimeInformation</th>
</tr>
</table>
<table id='myform'>
</table>
</form>
</body>
<script type="text/javascript">
function createRow()
{
var j = document.getElementById("numm").value;
var r = document.getElementById("myform");
var mf = document.getElementById("mform");
r.remove();
var r = document.createElement("TABLE");
r.setAttribute("ID", "myform");
mf.appendChild(r);
var n=0;
for(var k=0;k<j;k++)
{
var rr = document.createElement("TR");
r.appendChild(rr);
for(var i=1;i<3;i++)
{
var d = document.createElement("TD");
rr.appendChild(d);
var a = document.createElement("INPUT");
a.setAttribute("type", "text");
a.setAttribute("onkeyup", "formatCells"+i+"(this.value,'t"+i+"')");
a.setAttribute("Name", "t"+i+"_" + n );
d.appendChild(a);
n++;
}
}
}
function formatCells1(xls,group){
var m =0;
var arrGroup = null;
var arrGro = xls.split(" ");
for(var l=0;l<arrGro.length;l++)
{
arrGroup = arrGro[l].split("\t");
for(var i=0;i<arrGroup.length;i++){
document.forms[0].elements[group + "_" + m].value = arrGroup[i];
m=m+2;
}
}
}
function formatCells2(xls,group){
var m =1;
var arrGroup = null;
var arrGro = xls.split(" ");
for(var l=0;l<arrGro.length;l++)
{
arrGroup = arrGro[l].split("\t");
for(var i=0;i<arrGroup.length;i++){
document.forms[0].elements[group + "_" + m].value = arrGroup[i];
m=m+2;
}
}
}
</script>
</html>