[英]I have a problem with adding elements to my page after click - “Undefined”, what I need to do?
I am learning JS and I don't know what to do with this problem. 我正在学习JS,但不知道该怎么办。 A function must return something? 一个函数必须返回什么? If yes, what does it need to return? 如果是,它需要返回什么?
It is a part of my js: 这是我的js的一部分:
const workExamplesAdding = (htmlFirstText, htmlSecondText) => {
htmlFirstText += '<img src="/images/your_img_here1.png" alt="Example of our work" class="work-examples__item-img"><div class="work-examples__item-img--overlay"><a href="#" class="work-examples__item-link"><i class="far fa-eye"></i></a></div>';
htmlSecondText += '<img src="/images/your_img_here2.png" alt="Example of our work" class="work-examples__item-img"><div class="work-examples__item-img--overlay"><a href="#" class="work-examples__item-link"><i class="far fa-eye"></i></a></div>';
document.getElementById("work-examples__item--afterClick").innerHTML = htmlFirstText;
document.getElementById("work-examples__item--afterClick2").innerHTML = htmlSecondText;
document.getElementById("work-examples__item--afterClick3").innerHTML = htmlFirstText;
document.getElementById("work-examples__item--afterClick4").innerHTML = htmlSecondText;
document.getElementById("work-examples__item--afterClick5").innerHTML = htmlFirstText;
document.getElementById("work-examples__item--afterClick6").innerHTML = htmlSecondText;
document.getElementById("work-examples__item--afterClick7").innerHTML = htmlFirstText;
document.getElementById("work-examples__item--afterClick8").innerHTML = htmlSecondText;};
It is must look like this (without undefined): 它必须看起来像这样(没有未定义):
But it looks awful with undefined: 但是用undefined看起来很糟糕:
I can not give you html code, because Stack Overflow is warning that there is too much code. 我不能给你html代码,因为Stack Overflow警告说代码太多。
Calling function: 调用函数:
const btnClick = (elementIsClicked, element) => {
elementIsClicked = false;
function clickHandler() {
if (elementIsClicked = true) {
showText();
workExamplesAdding();
} else {
alert("Error");
};
};
// grab a reference to your element
element = document.getElementById('load-work-examples-btn');
// associate the function above with the click event
element.addEventListener('click', clickHandler);
}
哇,问题只是在“ htmlFirstText + = ...”中,我做了“ htmlFirstText = ...”,所以可以!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.