0

我正在尝试将 td 值传递给 java 脚本,从 java 脚本我将该值发布到它包含查询的 php 页面。任何人都可以指导我如何将 td 值传递给 java 脚本,我试过但我没有'不知道如何传递这个值。谢谢

下面是我的js代码:

<script>

function myFunction() {

 // Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var mcc = document.getElementById("mcc").value;
var mnc = document.getElementById("mnc").value;
var url = "testpage2/config.php";
var vars = "mcc="+mcc+"&mnc="+mnc;
hr.open("POST", url, true);
hr.send(vars); 

        }
</script>

html

<?php    
$sql = mysql_query("SELECT * FROM supplierprice ");   
    while($rows=mysql_fetch_array($sql))
{    
if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }           
echo '  <td class="edit region '.$rows["supp_price_id"].'">'.$rows["region"].'</td>
        <td class="edit country '.$rows["supp_price_id"].'">'.$rows["country"].'</td>
        <td class="edit networkname '.$rows["supp_price_id"].'">'.$rows["networkname"].'</td>
        <td id="mcc" class="edit mcc '.$rows["supp_price_id"].'">'.$rows["mcc"].'</td>   
        <td id="mnc" class="edit mnc '.$rows["supp_price_id"].'">'.$rows["mnc"].'</td>
        <td class="edit mnp '.$rows["supp_price_id"].'">'.$rows["mnp"].'</td>';           
    $ColumnNames = mysql_query("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'supplierprice' AND column_name NOT
IN ('supp_price_id','region', 'country', 'networkname', 'mcc', 'mnc', 'mnp'
)") or die("mysql error"); 
$columnArray=array();
$i=0;
while($rows1=mysql_fetch_array($ColumnNames))
{           
    $columnArray[]=$rows1[0];    
echo '<td  width="0px;" class="edit '.$columnArray[$i].' '.$rows["supp_price_id"].'">'.$rows[$columnArray[$i]].'</td>';   
        echo '<td><input type="button" onclick="myFunction()" value="" /></td>';        
                           $i++;
}
            echo '</tr>';
    }
            ?>
4

1 回答 1

2

value用于input元素。对于其他人(如td, th, div, span...),请使用innerHTML

var mcc = document.getElementById("mcc").innerHTML;
var mnc = document.getElementById("mnc").innerHTML;
于 2013-10-09T11:39:56.883 回答