0

我有这个功能,我想让var类别具有具有 id 的组合框的值#ticket_category_clone

我究竟做错了什么?

   function check () {
      var category="#ticket_category_clone";
          if (category=="Hardware")
      {
      SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');
      }
    }

    SPICEWORKS.app.helpdesk.ready(check);​

编辑

如果我以这种方式编写代码,它只会发出警报:

function check () {
    // var category = document.getElementById('#ticket_c_hardware_clone').value;
   var category ="Hardware";
   alert(category)
          if (category=="Hardware")
      {
        SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');


      }
   alert(category)
    }

SPICEWORKS.app.helpdesk.ready(check);

​</p>

像这样?http://img12.imageshack.us/img12/8438/semttuloluu.png

和代码:

<select id="ticket_category_clone" name="ticket[category]" hdpp="ticket_category"><option value=""></option>
4

3 回答 3

1

不知道 spiceworks,但在 JavaScript 中你可以这样做:

var category = document.getElementById("ticket_category_clone").value;

如果#是 id 的一部分,也添加它,但请注意它不是有效的 ID:

var category = document.getElementById("#ticket_category_clone").value;

看起来你需要一些调试。试试下面的代码:

var category = "";
var ddl = document.getElementById("ticket_category_clone");
if (ddl) {
    alert("found (1)");
    category = ddl.value;
} else {
    ddl = document.getElementById("#ticket_category_clone");
    if (ddl) {
        alert("found (2)");
        category = ddl.value;
    } else {
        alert("element can't be found");
    }
}
alert(category);

你收到什么警报?

于 2012-04-03T11:21:50.637 回答
0

This addition is probably late but if someone stumble on this they should know that SpiceWorks uses prototype.js as the JavaScript library. Therefore to get an element in the DOM you use the $ sign

So in order to get the combobox you use the following syntax

var e = $("#ticket_category_clone");
var category = e.options[e.selectedIndex].text;
于 2014-08-16T21:41:29.983 回答
0

你能用这条线测试吗?

var e = document.getElementById(""#ticket_category_clone");
var str = e.options[e.selectedIndex].text;

alert(str),如果你得到你想要的价值?

于 2012-04-03T21:05:15.323 回答