增加表格单元格的宽度和高度
increase width and height of table cells
我已经使用javascript动态创建了表格,想要添加一个"href"链接,当表格动态创建时,图像到表格单元格,并增加表格单元格的宽度和高度。请参阅"http://jsfiddle.net/c3X8Y/1/"。在"动作"列的表,我想显示的链接,并希望增加的宽度和高度的表单元格。下面是代码。HTML代码:
<input type="file" name="fileUpload" size="50" id="fileUploadID" multiple/></td>
</tr><br>
</table>
</td></tr> <tr><td>
<br/> <table border="1" id="uploadTable" style="visibility:hidden">
<tr> <th>SNo</th><th>FileName</th><th>Action</th> </tr>
</table>
Javascript代码:
<script>
var rowN = 1;var count = 1;var a=1;
document.getElementById("fileUploadID").onchange = function() {
document.getElementById("uploadTable").style.visibility="visible";
var fileNameIndex = document.getElementById('fileUploadID').value.lastIndexOf("''");
var file_name = document.getElementById('fileUploadID').value.substring(fileNameIndex + 1);
// Get a reference to the table
var tableRef = document.getElementById('uploadTable');
// Insert a row in the table at row index 1
var newRow = tableRef.insertRow(rowN);
// Insert a cell in the row at index 0
var newCell = newRow.insertCell(0);
// Append a text node to the cell
var newText = document.createTextNode(rowN);
newCell.appendChild(newText);
// Insert a cell in the row at index 1
var newCell2 = newRow.insertCell(1);
// Append a text node to the cell
var newText2 = document.createTextNode(file_name);
newCell2.appendChild(newText2);
// Insert a cell in the row at index 2
var newCell2 = newRow.insertCell(2);
// Append a text node to the cell
var newText2 = document.createTextNode('<a href="">delete</a>');
newCell2.appendChild(newText2);
rowN++;
}
</script>
不是创建一个html元素,而是在下面的代码中创建一个textNode:
// Append a text node to the cell
var newText2 = document.createTextNode('<a href="">delete</a>' +'<a href="">show</a>');
newCell2.appendChild(newText2);
相反,实际上必须使用createElement()
函数创建html元素,如下所示:
// Append a text node to the cell
var newText2 = document.createElement('a'); //create actual HTML element
newText2.innerHTML='show'; // set the elements properties
newText2.href="#";
newCell2.appendChild(newText2);
JSFiddle
这只是为了演示,你可以创建剩下的锚并设置它们的所有属性,如上面所示…
至于改变大小,只需在css中指定如下:
td{
width:250px;
height:250px;
}
JSFiddle
你可以设置动态创建元素的高度和宽度,如下所示:
newCell.style.width ='250px';
newCell.style.height ='250px';
要显示图像,只需创建<img>
并设置其源并对其单击事件执行逻辑,而不是创建<a>
。
JSFiddle
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 我应该使用Ng提交还是点击表格
- CSS表格:从列平移到整个表格宽度
- 单击页面上的链接后高度发生变化
- 将HTML表格导出到excel时,无法将数据加载到excel文件中
- 表格单元格高度与背景高度匹配
- 带有样式显示的 Div:表格的高度错误
- CSS表格高度
- 设置表格内文本区域的高度
- 有没有一种方法可以让表格单元格固定在给定的高度并启用换行
- Html表格:断字AND限制Td高度
- 使用jquery或javascript改变表格单元格的高度属性值
- 如何使文本区域与表格对齐并获取表格的高度
- 使HTML表格的高度等于中间TD元素的高度
- 增加表格单元格的宽度和高度
- 最大高度不'在表格标题上没有按预期工作
- 修复表格单元格's的高度
- 添加/删除CSS会导致IE9增加表格的高度