You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

外部JavaScript无输出问题排查:附HTML及JS代码

Troubleshooting Your Multiplication Script

Alright, let's fix this up for you—there are a couple of straightforward issues in your JavaScript code that are preventing the button from updating the page as expected:

Key Issues in demo.js

  • Variable Overwrite & Logical Mix-Up: You first calculate the product z = x * y, but then immediately re-declare z and try to assign the paragraph's content to it. This completely discards your calculation and does nothing to update the page. You need to reverse this logic: set the paragraph's content to your calculated product instead.
  • Case-Sensitive Property Name: JavaScript is case-sensitive, and the DOM property to update an element's content is innerHTML (note the uppercase HTML). You wrote innerhtml (all lowercase), which JS doesn't recognize as a valid property.

Corrected demo.js Code

function multiply() {
  var x, y, z;
  x = 5;
  y = 10;
  z = x * y;
  // Fix the property name and reverse the assignment logic
  document.getElementById('exp').innerHTML = z;
}

Quick Notes

Your HTML code is perfectly fine—since the JS file is in the same directory, the script tag's path works correctly. After updating demo.js with the code above, clicking the button will replace the "Multiplication result" text with 50, which is the product of 5 and 10.

内容的提问来源于stack exchange,提问作者Hashi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:09:14