javascript - 如何将信息传递给新功能
问题描述
需要知道如何将用户名、标题和formImg的信息从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;
function addNewPost(username, caption, imgLocation) {
}
解决方案
您可以在addNewPost
函数内部调用handleFormSubmit
函数并传递值。
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) {
}
推荐阅读
- amazon-web-services - 尽管 IAM 设置正确,Terraform 仍承担角色
- java - 流式处理直接从函数返回的 Java 集合
- android - 无法在 Android Studio 北极狐中隐藏弹出窗口提取方法
- html - CSS - 将子 div 拉伸到其溢出的父级的完整高度
- xcode - @Published 值不重绘视图 SwiftUI
- javascript - 在 Azure Blob 存储上上传大型 Blob 时延长令牌过期时间
- algorithm - 创建嵌套结构的算法
- asp.net-core - 安装 .Net 6 - Preview 7 后,如何修复 Asp.Net Core 应用程序中的 Microsoft.NETCore.App.Host.win-x64 编译器错误?
- angular - How to filter console.log when using Angular Karma Jasmine
- python - 如何使用 lmdb 形成树形数据库结构