Is it possible to get the value of a lt;tdgt; element using onclick?(是否有可能得到一个 lt;tdgt; 的值?使用 onclick 的元素?)
问题描述
我目前有一个表格,其中包含使用 php 回显的电子邮件模板名称列表.下面是部分php代码.我正在尝试获取表值并将其传递给我的 JS 文件,未来的 AJAX 命令会将其传递给另一个文件(我不会有任何问题).我第一次尝试提醒该值表明该值未定义.我的第二次尝试显示了它内部的元素类型(当时它是一个跨度).现在它什么也没有显示.有什么建议吗?
I currently have a table that has a list of email template names being echoed using php. Below is part of the php code. I'm trying to grab the table value and pass it to my JS file where a future AJAX command will pass it to a different file (that I won't have any issues with). My first attempt to alert out the value stated that the value was undefined. My second attempt showed the type of element it was inside (at the time it was a span). Now it's not showing anything. Suggestions?
PHP 代码:
<table class="departments">
<tr>
<th scope="col" style="width: 175px;">Email Name</th>
';
$get_depts = mysql_query("SELECT dept_name FROM depts where bus_id = '{$_SESSION['bus_id']}'");
while(($department = mysql_fetch_assoc($get_depts)))
{
echo '
<th scope="col" style="width: 175px;">'.$department['dept_name'].'</th>
';
}
echo '
</tr>
';
$get_emails = mysql_query("SELECT id, email_name from emails where bus_id = '{$_SESSION['bus_id']}' ORDER BY email_name ASC");
while(($email = mysql_fetch_assoc($get_emails)))
{
echo '
<tr>
<td id="test" onclick="moveValue()">'.$email['email_name'].'</td>
';
当前 JS 代码:
function moveValue()
{
var x = document.getElementById(test);
var y = x.innerHTML;
alert(y);
}
推荐答案
Javascript:
Javascript:
var y = document.getElementById("test").innerText;
jQuery:
$("#test").text();
获取 HTML:
var html = document.getElementById("test" ).innerHTML;
jQuery:
$("#test").html();
这篇关于是否有可能得到一个 <td> 的值?使用 onclick 的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有可能得到一个 <td> 的值?使用
基础教程推荐
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
