动画添加一个表行(JavaScript + jQuery)
Animating adding a table row (JavaScript + jQuery)
我已经编写了一些代码来添加一个表行,如下所示。
function addRow(pos) {
// Insert new HTML table row
var tblObj = document.getElementById('questionTbl');
var newRow = tblObj.insertRow(pos + 1);
// Add new table cells
var newCell1 = newRow.insertCell(0);
newCell1.innerHTML = 'one';
var newCell2 = newRow.insertCell(1);
newCell2.innerHTML = 'two';
var newCell3 = newRow.insertCell(2);
newCell3.innerHTML = 'three';
var newCell4 = newRow.insertCell(3);
newCell4.innerHTML = 'four';
var newCell5 = newRow.insertCell(4);
newCell5.innerHTML = 'five';
var newCell6 = newRow.insertCell(5);
newCell6.innerHTML = 'six';
var newCell7 = newRow.insertCell(6);
newCell7.innerHTML = 'seven';
我已经添加了jQuery库,因为我想要一些我没有预见到的功能(否则我会在查询中添加行)。
newRow.id = "row_" + (pos + 1);
newRow.className = "hide";
$(document).ready(function() {
$("#row_" + (pos + 1)).switchClass("hide", "show-row");
});
行添加工作,但它不动画。它的出现有延迟(我猜这是动画所需的时间)。
有谁知道为什么动画不工作吗?
谢谢。
试试这个
$(document).ready(function() {
$("#row_" + (pos + 1)).removeClass("hide").addClass("show-row").hide().show('slow');
});
试试这个:
function addRow(pos) {
// Insert new HTML table row
var tblObj = document.getElementById('questionTbl');
var newRow = tblObj.insertRow(pos + 1);
// Add new table cells
var newCell1 = newRow.insertCell(0);
newCell1.innerHTML = 'one';
var newCell2 = newRow.insertCell(1);
newCell2.innerHTML = 'two';
var newCell3 = newRow.insertCell(2);
newCell3.innerHTML = 'three';
var newCell4 = newRow.insertCell(3);
newCell4.innerHTML = 'four';
var newCell5 = newRow.insertCell(4);
newCell5.innerHTML = 'five';
var newCell6 = newRow.insertCell(5);
newCell6.innerHTML = 'six';
var newCell7 = newRow.insertCell(6);
newCell7.innerHTML = 'seven';
newRow.id = "row_" + (pos + 1);
newRow.className = "hide";
$("#row_" + (pos + 1)).switchClass("hide", "show-row");
}
$(document).ready(function() { ... }
应该在需要代码在DOM准备好被操作时立即执行时使用,基本上传递给ready
函数的函数在页面加载时执行。原来的jQuery代码永远不会执行,因为在ready事件已经被触发后,函数被附加到ready 事件。
相关文章:
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- Javascript(jQuery)给了我奇怪的结果
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- Javascript/jQuery中的并行Ajax调用
- 我可以在Javascript/jQuery中使用一个变量作为键吗
- Javascript/Jquery/PHP加载页面-如何
- Javascript/Jquery Blob not showing Chrome PDF
- 如何使用javascript/jquery获取iframe的URL的锚点属性
- OnClick/Onhover Javascript/jquery
- 如何从javascript/jquery中的复选框中获取布尔值
- javascript/jquery将utc转换为短格式的本地时间
- 在不设置协议的情况下,使用javascript/jquery更改iframe-src
- 如何向这个javascript/jquery函数添加参数
- 用JavaScript/jQuery点击图片,选中多个方框
- 使用Javascript/JQuery获取JSON GET数据
- 从数组中删除元素的最佳方法是:javascript/jquery
- Javascript/jQuery压缩一个图像正确的评论帖子,并使用Ajax Laravel 5.2保存到控制器中
- 用DRY方式Javascript/JQuery动态替换HTML
- 类似Javascript JQuery的库
- 如何在 Javascript/jQuery 中获取一些随机下拉列表的选定值