how can i get the value of a td
-
29-05-2021 - |
题
i want to get the value of this td
my code
function check() {
var e = document.getElementById("ticket_category_clone");
var str = e.options[e.selectedIndex].text;
alert(str);
if (str === "Hardware") {
SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');
}
}
SPICEWORKS.app.helpdesk.ready(check);
and bang it does Nothing, what could be the problem?
the html srry for not post it in the begging
<select id="ticket_category_clone" name="ticket[category]" hdpp="ticket_category">
<option value=""></option><option value="Hardware">Hardware</option>
<option value="Software">Software</option>
<option value="Rede" selected="selected">Rede</option>
<option value="Pedidos">Pedidos</option>
<option value="Formação/Dúvida">Formação/Dúvida</option>
<option value="Outro">Outro</option><option value="#edit_categories#">Edit Categories...</option></select>
解决方案
You could use
var e = document.getElementById("td.body-c_hardware.cell-c_hardware");
var str = e.innerHTML;
其他提示
To use getElementById, your tag needs an id
<table>
<tr><td id="idValue">Content</td></tr>
</table>
and you need to fetch it by just using the id value
document.getElementById('idValue');
If you want to use CSS-like selectors, you may be best using a toolkit like jQuery
jQuery('#idValue');
jQuery('td.className');
jQuery('table.tableClass td.cellClass');
You need to get the select element by its id. You can then access either the text of the option or the value of the option. I think you may want the value instead of the text. I have posted a solution for both ways.
var e = document.getElementById('ticket_category_clone');
alert(e.options[e.selectedIndex].innerHTML);
If you want the actual value, and not the text then use this instead. I suspect it might be what you want.
var e = document.getElementById('ticket_category_clone');
alert(e.value);
不隶属于 StackOverflow