Javascript 如何将信息传递给新函数
需要知道如何将用户名、标题和格式信息从handleFormSubmit传递到addNewPostJavascript 如何将信息传递给新函数,javascript,Javascript,需要知道如何将用户名、标题和格式信息从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 = documen
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) {
}
您可以在handleFormSubmit
函数中调用addNewPost(用户名、标题、格式)
。确保在handleFormSubmit
函数之外声明了addNewPost()