简体   繁体   English

javascript if else 语句不起作用。 即使我单击 twoStory 图像,它也会返回 singleStory。 我试过了!=和---

[英]javascript if else statement not working. It returns singleStory even if I click on the twoStory image. I have tried != and ---

const detailedEstimate = () => {
document.querySelector("#btnDisplayImage").onclick = () => {


let houseStoriesLabel = document.createElement("label");
houseStoriesLabel.innerHTML = "<br>" + "number of stories is " + houseStory + "<br>";
document.body.appendChild(houseStoriesLabel);


if (houseStory = singleStory) {
  houseStory.setAttribute("src", "../images/singleStoryHouse.jpg");
  document.body.appendChild(houseStory);
  console.log('please make a choice');
}

You need:你需要:

if (houseStory === singleStory)

not不是

if (houseStory = singleStory)

The single equals sign assigns the value of singleStory to houseStory .单等号singleStory的值分配给houseStory === is what does comparison (or the much-frowned-upon == ). ===是比较(或令人不悦的== )。

暂无
暂无

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

相关问题 我在 Javascript 控制台中有一个循环不起作用。 一种 - I have a loop in the Javascript console that is not working. A 此 JavaScript 代码不起作用。 我的语法错误还是其他原因? - This JavaScript code is not working. Have I got the syntax wrong or is it something else? 如果javascript中的else语句不起作用。 仅在else语句中 - if else statement in javascript is not working. only in else statement django rest 框架甚至显示上传图像的选项。 我在模型中有 imageField - django rest framework dosent even show the option to upload image. I do have imageField in models JavaScript classList不起作用。 我尝试了在这里看到的各种方法 - JavaScript classList is not working. I've tried various methods I've seen on here 我的切换器不工作。 我试过将 js cdn 放在顶部和底部,但没有用 - My toggler is not working. I have tried placing js cdn in top and bottom both but didn't work 我有一个脚本来调整图像大小。 无论如何让它输出5张图像? - I have a script to resize an image. Is there anyway to have it output 5 images? if else if 语句没有按我想象的方式工作 - the if else if statement not working the way I thought would have worked 我尝试创建一个仅运行一次但始终运行 else 语句的 javascript function - i tried creating a javascript function that only runs once but its always running the else statement 我想使成功通知和错误通知在通知后4秒钟后消失,但是尝试不起作用。 - I want to make the success notification and error notification fade after 4 seconds after the notification but have tried doing it not working.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM