javascript - Html按钮不显示表单

标签 javascript html

这是我的代码。我创建了一个按钮,在单击事件时我想显示表单,但我的表单未显示。

gives an error " Uncaught SyntaxError: Invalid or unexpected token"

<input id="Result" name="display" type="button" value="Cost Report" onclick=  document.getElementById("form id").style.display="block";
      style="overflow:hidden;padding: 5px 5px; border-radius: 3px;font-size: 8.5pt; width:200px ; background-color: #E7FCCA; font-weight: bold; ">
    
    <div> 
        <form id="form id" style="display: block;">Results</form>
    </div>

最佳答案

将事件绑定(bind)到元素时,应使用 "' 包裹它们。

<input id="Result" name="display" type="button" value="Cost Report" onclick='document.getElementById("form id").style.display="block";' style="overflow:hidden;padding: 5px 5px; border-radius: 3px;font-size: 8.5pt; width:200px ; background-color: #E7FCCA; font-weight: bold; ">

<div>
  <form id="form id" style="display: none;">Results</form>
</div>

关于javascript - Html按钮不显示表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751506/

相关文章:

javascript - jQuery 函数在 JSFiddle 上工作,但在我的 html 文档中不起作用

javascript - 元素后的 HTML 脚本标签

javascript - 在网站顶部放置一个 HTML 按钮?

javascript - 无法隐藏我使用 javascript 和 jquery 生成的 html 元素

javascript - 如何使用 CSS 在 AngularJS 中换行文本?

javascript - Neo4j - 根据关系属性计算和设置节点属性

javascript - 保存用户在网站上的输入

javascript - jQuery:向元素内的数字加一

javascript - 将多属性项推送到数组 JAVASCRIPT

css - 页面中并排放置 2 个 div