我怎样才能得到一个TD

问题描述:

我想这td我怎样才能得到一个TD

我的代码

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); 

价值和Bang它什么都不做,什么可能是问题的价值?

的HTML srry在乞讨

<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> 
+1

HTML是什么样的?不管它看起来如何,如果你拿到一个'​​',很期待它有一个“选项”属性。你确定你不是在寻找一个'

+0

哦srry我忘了发布img – user181891 2012-04-05 15:15:27

+0

@Pointy现在只发布了img – user181891 2012-04-05 15:18:10

不要发布你可以使用

var e = document.getElementById("td.body-c_hardware.cell-c_hardware"); 
var str = e.innerHTML; 

要使用getElementById,你的标签需要一个ID

<table> 
    <tr><td id="idValue">Content</td></tr> 
</table> 

,你需要通过使用id值来获取它

document.getElementById('idValue'); 

如果你想使用类似CSS选择器,你可以使用的工具包如jQuery

jQuery('#idValue'); 
jQuery('td.className'); 
jQuery('table.tableClass td.cellClass'); 

您需要通过其ID来获得选择元素是最好的。然后您可以访问选项的文本或选项的值。我想你可能想要的是价值而不是文字。我已经发布了两种解决方案。

http://jsfiddle.net/c4eWg/1

var e = document.getElementById('ticket_category_clone'); 
alert(e.options[e.selectedIndex].innerHTML); 

如果你想实际值,而不是文本,然后用这个来代替。我怀疑这可能是你想要的。

var e = document.getElementById('ticket_category_clone'); 
alert(e.value); 
+0

它的剂量做任何事情我认为它的问题来自spiceworks – user181891 2012-04-05 15:43:25

+0

很抱歉听到这个!希望你弄明白。 – mrtsherman 2012-04-05 16:08:04

+0

无论如何thinx帮助 – user181891 2012-04-05 16:08:34