如何使用javascript获取动态生成的表的值

时间:2014-02-06 08:18:19

标签: javascript php html

这里我试图使用javascript <td> value </td>获取getElementById(ID);内的值,但我无法在警告框中获取值和显示值。

代码:

<script type="text/javascript">
function getvalue()
{
var lat = document.getElementById('lat').value;
var lon = document.getElementById('lon').value;
var lati = parseInt(lat);
var long = parseInt(lon);
alert(lati,long);
}
</script>

php-html代码:

while($row = mysql_fetch_assoc($retval))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['theater_name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td id='lat'>" . $row['lat'] . "</td>";
echo "<td id='lon'>" . $row['lon'] . "</td>";
echo "</tr>";
}

该表由php从数据库表值自动生成,仅用于一条记录。现在我想在javascript中获取lat和lon值并提醒它..但现在我无法获得警报......我该怎么做?

1 个答案:

答案 0 :(得分:4)

var lat = document.getElementById('lat').innerHTML;
var lon = document.getElementById('lon').innerHTML;

value适用于<form>个元素(<input><select>等等。)