简体   繁体   English

当我使用 javascript 函数按类获取元素时,它向我显示 [object HTMLCollection] 而不是 div 中的值

[英]when i am using javascript function to get elemen by class it shows me [object HTMLCollection] not the value inside the div

I have also convert the variable s to string but the result is same what to do how to get the value by class.我还将变量 s 转换为字符串,但结果与如何按类获取值相同。

function myFunction() {
   var s = document.getElementsByClassName('clinic-timings-day');
   alert(s);
   document.getElementById('#mine').innerHTML = s[0].toString();
   alert("test2");
}

<body>
   <p class="clinic-timings-day">MON, WED</p>
   <a onclick="myFunction()">Try it</a>
</body>

Your made few mistakes on your function.您在功能上犯了一些错误。

  var s = document.getElementsByClassName('clinic-timings-day').innerHTML;

  document.getElementById('mine').innerHTML = s[0].toString();

暂无
暂无

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

相关问题 如何使用javascript获取div内的div值? - How do I get the value of a div inside a div using javascript? 如何<span>在使用 JavaScript 的链接的 HTMLCollection 内的文本中<a>使用 select 文本?</a></span> - How do I select text inside a <span> that is inside an HTMLCollection of links <a> using JavaScript? 我试图获得使用return函数的附加值,但没有得到| 您能帮助我我到底在做什么错吗? - I am trying to get the addition value of using return function but not getting | Could you help to me what exactly I am doing wrong? 使用JavaScript获取DIV类的值 - Get value of class of a DIV using JavaScript 在Div Javascript中获取价值 - Get value inside Div Javascript 在 javascript 中获取 div 内的值 - Get value inside div in javascript 我在 javascript 中使用 onkeyup function 并且如果我按下键然后我得到不同的 ASCII 值 - I am using onkeyup function in javascript and If I press key then I get different ASCII value 我如何在javascript函数内为div添加类 - How can i add class for div inside of javascript function 试图从JavaScript .innerHTML正确的功能中理解[object HTMLCollection]吗? - Trying to make sense of [object HTMLCollection] From JavaScript .innerHTML Right Function? 我正在尝试使用javascript获取jsp中文本框的值。但是我无法获取。请给我一些如何获取的建议 - I am trying to get the value of a textbox in jsp using javascript.But i am unable to get.please give me some suggestion how to get it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM