判断 html 表的行数,如何计算动态生成的html表中的行数?

任何人都可以请帮我算一个使用JavaScript的动态生成HTML表格的行数吗?如果任何人都可以在此帮助让我知道,我已经试图动态生成行的数据插入到数据库如何计算动态生成的html表中的行数?

我JS代码:

var count=1;

function addRow(tableID) {

/*if(empty(index))

{

var index = 0;

}

else

{

index++;

alert(index);

document.getElementById('cat').name = 'cat'+index;

}*/

var table = document.getElementById(tableID);

var rowCount = table.rows.length;

var count = rowCount-1;

alert(rowCount);

var selectOFCat = $("#"+tableID).find('tr:eq(0)').find('.cat').get(0);

var row = table.insertRow(rowCount);

var colCount = table.rows[0].cells.length;

for(var i=0; i

var newcell = row.insertCell(i);

newcell.innerHTML = table.rows[0].cells[i].innerHTML;

//alert(newcell.childNodes);

switch(newcell.childNodes[0].type) {

case "text":

newcell.childNodes[0].value = "";

break;

case "checkbox":

newcell.childNodes[0].checked = false;

break;

case "select-one":

newcell.childNodes[0].selectedIndex = 0;

break;

}

}

$(table).find("tr:eq("+rowCount+")").find('.cat').attr("id","cat"+rowCount);

}

function deleteRow(tableID) {

try {

var table = document.getElementById(tableID);

var rowCount = table.rows.length;

for(var i=0; i

var row = table.rows[i];

var chkbox = row.cells[0].childNodes[0];

if(null != chkbox && true == chkbox.checked) {

if(rowCount <= 1) {

alert("Cannot delete all the rows.");

break;

}

table.deleteRow(i);

rowCount--;

i--;

}

}

}catch(e) {

alert(e);

}

}

function changeSelection(value){

var length = document.getElementById("ind").options.length;

if(value == "All"){

for(var i = 1;i

document.getElementById("ind").options[i].selected = "selected";

document.getElementById("ind").options[0].selected = "";

}

}

我的PHP代码:

Add your Products
   
::TypeProductSpecificationOptionSourceFrequencyQuantityUnit

--Select a Category--

= $options ?>

<?php echo tep_draw_input_field('data[productname][]','','class="srcinfo"'); ?>

echo tep_draw_checkbox_field('data[option][]','sell', false).' Sell'; ?>

$source_array[0] = array('id' => 'All', 'text' => 'All India');

$source_array[1] = array('id' => 'AP', 'text' => 'Andhra Pradesh');

$source_array[2] = array('id' => 'ARP', 'text' => 'Arunachal Pradesh');

$source_array[3] = array('id' => 'ASM', 'text' => 'Assam');

$source_array[4] = array('id' => 'BHR', 'text' => 'Bihar');

$source_array[5] = array('id' => 'DL', 'text' => 'Delhi');

echo tep_draw_pull_down_menu('data[source][]', $source_array,'','class="srcinfo_source" multiple οnchange="changeSelection(this.value)" id="ind"'); ?>

$frequency_array[0] = array('id' => 'Yr', 'text' => 'Yearly');

$frequency_array[1] = array('id' => 'mnth', 'text' => 'Monthly');

echo tep_draw_pull_down_menu('data[freq][]', $frequency_array,'','class="srcinfo" style="margin-top:50px;"'); ?>

$unit_array[0] = array('id' => 'kg', 'text' => 'kilogram');

$unit_array[1] = array('id' => 'gr', 'text' => 'gram');

$unit_array[2] = array('id' => 'mg', 'text' => 'milligram');

echo tep_draw_pull_down_menu('data[unit][]', $unit_array,'','class="srcinfo" style="margin-top:50px;"'); ?>

<?php echo tep_draw_button(IMAGE_BUTTON_PRODINFO, 'person', null, 'primary',array('params' => 'name="add_pro" class="btn btn-danger" ')); ?>

if(isset($_POST['add_pro']))

{

foreach($html->find('dataTable') as $table){

$all_trs = $table->find('tr');

$count = count($all_trs);

echo $count;

exit;

}

$src = $_POST['source'];

$products_source = implode(",", $src);

$opt = $_POST['option'];

$products_options = implode(",", $opt);

$products_array = array(

'products_quantity' => $products_quantity,

'products_date_added' => 'now()',

'products_source' => $products_source,

'products_frequency' => $products_frequency,

'products_options' => $products_options,

'products_unit' => $products_unit,

'customers_id' => $customer_id

);

tep_db_perform(TABLE_PRODUCTS, $products_array);

$products_desc_array = array(

'products_name' => $products_name,

'products_description' => $products_description

);

tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $products_desc_array);

$prod_id = tep_db_insert_id();

$category_id_array = array('products_id' => $prod_id,

'categories_id' => $category_type_id);

tep_db_perform(TABLE_PRODUCTS_TO_CATEGORIES, $category_id_array);

$update_stage = tep_db_query("update " . TABLE_CUSTOMERS . " set customers_stage='5' where customers_id = '" . $customer_id. "'");

tep_redirect(tep_href_link(FILENAME_REGISTRATION_6, '', 'SSL'));

}

?>

我想插入行中的值在动态生成的窗体中。

+0

清楚地陈述你的问题,用你尝试的一些适当的代码,并为你的问题添加适当的标签......! –

+1

为什么这个标签为“php”? –

+1

你还尝试过什么吗? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值