我怎么能得到一个HTML按钮通过一个函数传递表单的字符串

How can I get a HTML button to pass a form`s string through a function?

本文关键字:一个 函数 字符串 表单 HTML 怎么能 按钮      更新时间:2023-09-26

我有以下表单和按钮:

home。

<input class="draft" type="text" id="message" placeholder="Write your msg here!"/> 
<button class="send">Send</button>

我需要的字符串,将填写在表单传递给Chat.send()函数下面作为参数:

Applications.js

$("#button").click(function(){
  Chat.send();
})

如何将两者联系在一起?

您可以尝试这样做:

$("#button").click(function(){
  Chat.send($('#message').val());
});

假设您将id="button"添加到按钮中,否则使用button.send

选择器。
$("button.send").click(function(){
    var text = $("input#message").val();
    Chat.send(text);
});