2011-03-09 34 views
0

GET_COOKIE('CURRENT_IM')将返回保存在CURRENT_IM cookie中的数字。我怎样才能使这个工作?使用函数getElementById()获取元素的ID

这是在onclick属性

document.getElementById('IM_INNER_'+GET_COOKIE('CURRENT_IM')).style.display='none'; 
+1

onclick属性是单引号还是双引号? – 2011-03-09 02:07:10

+0

双引号,它说document.getElementById(“IM_INNER_”+ GET_COOKIE(“CURRENT_IM”))为空 – 2011-03-09 02:08:35

+1

你可以上传一些源代码在jsfiddle(http://jsfiddle.net/) – mellamokb 2011-03-09 02:09:38

回答

0

什么是不工作?

我的调试立即想到将设置一个变量。此外,在整数返回值上调用toString()可能会有所帮助。

var id = 'IM_INNER_'+GET_COOKIE('CURRENT_IM').toString(); 
    alert(id); //this will tell you what the id is. you can view the source to see if it's correct 
    document.getElementById(id).style.display='none'; 
+0

我得到“IM_INNER_” – 2011-03-09 02:14:08

+0

GET_COOKIE没有返回任何内容? – JCOC611 2011-03-09 02:15:04

+1

这意味着GET_COOKIE函数已损坏并返回空值。 – smartcaveman 2011-03-09 02:15:12