Javascript 计算动态行数并在html的输入框中显示
我曾尝试计算html表中的动态行数,在计算行数时,它也在计算表头,我希望在输入框中显示行数Javascript 计算动态行数并在html的输入框中显示,javascript,html,Javascript,Html,我曾尝试计算html表中的动态行数,在计算行数时,它也在计算表头,我希望在输入框中显示行数 $(document).ready(function(){ $(".count").click(function(){ // Select all the rows in the table // and get the count of the selected elements var rowCo
$(document).ready(function(){
$(".count").click(function(){
// Select all the rows in the table
// and get the count of the selected elements
var rowCount = $("#tbpnr tr").length;
var x = document.write(rowCount*280).innerHTML;
return(x);
document.getElementById("answer").value = x;
});
});
此代码将计算表体中的行数,并将行数*280放入输入元素
$(文档).ready(函数(){
$(“.count”)。单击(函数(){
var rowCount=$(“#tbpnr tr”)。长度;
document.getElementById(“count”).textContent=rowCount;
document.getElementById(“answer”).value=rowCount*280;
});
});代码>
计数
行数:
行数*280:
您可以使用jQuery
本身在输入
框中添加计数。
请尝试以下代码,以便在input
中显示计数
$(document).ready(function(){
$(".count").click(function(){
// Select all the rows in the table
// and get the count of the selected elements
var rowCount = $("#tbpnr tr").length;
$("#answer").attr("value", rowCount*280)
});
});
请添加表格的HTML以解决表格标题计数问题。我们也需要HTMLdocument.write(rowCount*200).innerHTML代码>将不起作用<代码>返回(x)
将不起作用。最后一行代码将永远不会执行。请将您的标记添加到问题中