JavaScript, getting value of a td with id name

后端 未结 8 1432
难免孤独
难免孤独 2020-12-01 02:53

Originally I was using input with an id and grabbing it\'s value with getElementById. Currently, I\'m playing with s. How can I grab the values of the

相关标签:
8条回答
  • 2020-12-01 03:13

    if i click table name its shown all fields about table. i did table field to show. but i need to know click function.

    My Code:

    $sql = "SHOW tables from database_name where tables_in_databasename not like '%tablename' and tables_in_databasename not like '%tablename%'";
    
    
    $result=mysqli_query($cons,$sql);
    
    $count = 0;
    
    $array = array();
    
    while ($row = mysqli_fetch_assoc($result)) {
    
        $count++;
    
        $tbody_txt .= '<tr>';
    
        foreach ($row as $key => $value) {
            if($count  == '1') {
                $thead_txt .='<td>'.$key.'</td>';
            }
            $tbody_txt .='<td>'.$value.'</td>';
    
    
            $array[$key][] = $value;
        }
    }?>
    
    0 讨论(0)
  • For input you must have used value to grab its text but for td, you should use innerHTML to get its html/value. Example:

    alert(document.getElementById("td_id_here").innerHTML);
    

    To get its text though, use:

    alert(document.getElementById("td_id_here").innerText);
    
    0 讨论(0)
  • 2020-12-01 03:16

    .innerText doesnt work in Firefox.

    .innerHTML works in both the browsers.

    0 讨论(0)
  • 2020-12-01 03:18

    Again with getElementById, but instead .value, use .innerText

    <td id="test">Chicken</td>
    document.getElementById('test').innerText; //the value of this will be 'Chicken'
    
    0 讨论(0)
  • 2020-12-01 03:23

    Have you tried: getElementbyId('ID_OF_ID').innerHTML?

    0 讨论(0)
  • 2020-12-01 03:29

    If by 'td value' you mean text inside of td, then:

    document.getElementById('td-id').innerHTML
    
    0 讨论(0)
提交回复
热议问题