未捕获的引用错误:变量未在单击函数上定义

Uncaught ReferenceError: variable is not defined on onclick function

本文关键字:单击 函数 定义 变量 引用 错误      更新时间:2023-09-26

我是编码新手,但很难弄清楚为什么我在 Chrome 中的"添加新任务"按钮上收到 referenceError 而没有任何反应。

这是我创建视图的函数,我正在尝试使用一个 onclick 函数来调出一个带有字段的灯箱。

"添加新任务"按钮位于代码段的底部

感谢您的帮助!

    <script type="text/javascript">
      function action_form(id) {
          $("#dialog_form").remove();
          $("#tasks-form").append('
        <div id="dialog_form"></div>');
          $("#dialog_form").attr("title", (id !== undefined ? "Edit task" : "Create new task"));
          $("#dialog_form").html('
        <div>' + '
    </script>
    <div class="blocks">
      <h1>Tasks for your MultiScraper</h1>
      <div class="text-block">
        <input type="button" value=" + Add new task" class="btn btn-blue" onclick="action_form();" id="tasks_add_button" style="float: right;margin: 10px 30px 10px 0;" />
        <input type="button" value="Products grabbed" class="btn btn-grey" onclick="" id="tasks_grabbed_product_button" style="float: left;margin: 10px 30px 10px 30px;" />
        <div class="clear"></div>
        <div id="tasks-form" class="ms_form" style="padding: 10px;width: 1240px;padding-bottom: 0;">
          <div id="form-content">
            <table class="list" id="parser_instruction_table">
              <thead>
                <tr id="instruction_table_header">
                  <td colspan="10">You have not yet made ​​any task for your MSPRO. Please, create the first one</td>
                </tr>
              </thead>

function action_form(id) {
    $("#dialog_form").remove();
    $("#tasks-form").append('
                           <div id="dialog_form"></div>');
    $("#dialog_form").attr("title", (id !== undefined ? "Edit task" : "Create new task"));
    $("#dialog_form").html('
                          <div>' + '

在写入字符串时留换行符,就像在

$("#tasks-form").append('
                       <div id="dialog_form"></div>');

$("#dialog_form").html('
                      <div>' + '

将导致错误。

$("#tasks-form").append('<div id="dialog_form"></div>');

或者,如果您必须换行

$("#tasks-form").append('' +
                       '<div id="dialog_form"></div>');

另外,有问题

$("#dialog_form").html('<div>' + '

看起来您忘记关闭函数的括号和括号