gpt4 book ai didi

javascript - 如何将信息传递给新功能

转载 作者:行者123 更新时间:2023-11-30 13:46:43 25 4
gpt4 key购买 nike

需要知道如何传递username、caption、formIng等信息来从handleFormSubmit添加Post

function handleFormSubmit(event) {
// This next line prevents the reload of the form
event.preventDefault();
// Get values of inputs
// Pass values to addNewPost()
var username = document.getElementById("formUsername").value;
var caption = document.getElementById("formCaption").value;
var formImg = document.getElementById("formImg").value;

function addNewPost(username, caption, imgLocation) {




}

最佳答案

您可以在handleFormSubmit 函数中调用addNewPost 函数并传递值。

function handleFormSubmit(event) {
// This next line prevents the reload of the form
event.preventDefault();
// Get values of inputs
// Pass values to addNewPost()
var username = document.getElementById("formUsername").value;
var caption = document.getElementById("formCaption").value;
var formImg = document.getElementById("formImg").value;

addNewPost(username, caption, formImg ); // call the function here.
}
function addNewPost(username, caption, imgLocation) {


}

关于javascript - 如何将信息传递给新功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59167883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com