简体   繁体   English

使用函数通过getElementById()获取元素的ID

[英]Using a function to get the ID of an element with getElementById()

GET_COOKIE('CURRENT_IM') will return a number saved in the CURRENT_IM cookie. GET_COOKIE('CURRENT_IM')将返回保存在CURRENT_IM cookie中的数字。 How can I get this to work? 我该如何工作?

This is in a onClick Attribute 这是在onClick属性中

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

What is not working? 什么不起作用?

My immediate thought for debugging would be to set a variable. 我立即想到的调试方法是设置一个变量。 Also, calling the toString() on the integer return value may help. 此外,调用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';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有getElementById的情况下获取元素的ID - How to get Id of an element without getElementById 如何使用元素的id和getElementById获取其他特定元素内的元素? - How to get element inside other specific element using its id and getElementById? 如何使用getelementbyId为id作为数组获取值 - How to get value using getelementbyId for id as array 将HTML元素作为函数传递给函数,而不是使用getElementById获得相同的元素 - passing HTML element as an arguvment to a function vs. using getElementById to get same element 有没有一种方法可以像使用getElementById()可以获取html元素对象一样使用函数“获取” javascript对象? - Is there a way to “get” javascript objects using a function in the same way getElementById() is able to get html element objects? 如何将元素的ID作为参数传递给使用getElementById的函数? - How to pass the element's ID as an argument to a function which uses getElementById? 获取由Document.getElementByID(“ id_name”)选择的元素的索引 - get index of element selected by Document.getElementByID(“id_name”) 如果元素“隐藏”,如何使用GetElementByID保留ID - How do I get ahold of the ID with GetElementByID if the element is “hidden” getElementById不是用于显示元素的函数 - getElementById not a function for displaying element getElementById和简单地使用元素的ID作为变量有什么区别? - What is the difference between getElementById and simply using an element's ID as a variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM