为什么价值不传递到控制台?

时间:2019-01-08 23:10:04

标签: javascript jquery

这是一个愚蠢的问题,但我感到沮丧,并希望获得一些帮助。提交后,为什么我的值不输出到控制台?有人注意到问题吗?

var todos = "";

// user clicked on the add button in the to-do field add that text into the to-do text

$('#add-todo').on('click', function(event) {
  event.preventDefault();

  //values per text box
  todos = $("#todo-input").val().trim();

  //test values from textbox
  console.log(todos);

HTML

<div class ="col-4">
    <form role = "form">
        <div class = "form-group row">
            <div class = "To-Do-List">
                <label for="todo-input">Add Your To Do List Here:</label>
            </div>
            <input class="form-control" id="todo-input" type = "text">
            <tbody id = "table_body">
            </tbody>
        </div>
    </form>
</div>
<div class="button">
    <button class ="btn btn-danger" id="add-todo" type="submit">Add</button>
</div>

1 个答案:

答案 0 :(得分:1)

您只需要关闭“}}”

var todos = "";

// user clicked on the add button in the to-do field add that text into the to-do text

$('#add-todo').on('click', function(event) {
  event.preventDefault();

  //values per text box
  todos = $("#todo-input").val().trim();

  //test values from textbox
  console.log(todos);

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class ="col-4">
    <form role = "form">
        <div class = "form-group row">
        <div class = "To-Do-List">
            <label for="todo-input">Add Your To Do List Here:</label>
        </div>
        <input class="form-control" id="todo-input" type = "text">
            <tbody id = "table_body">
            </tbody>
        </div>
    </form>
</div>
<div class="button">
<button class ="btn btn-danger" id="add-todo" type="submit">Add</button></div>