Javascript 提交后如何在同一页面中显示html表单值?
可以给我一个例子,从提交按钮后的输入中提取数据,并在同一页面中发送到输出h2吗 这是我的输入和提交按钮Javascript 提交后如何在同一页面中显示html表单值?,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,可以给我一个例子,从提交按钮后的输入中提取数据,并在同一页面中发送到输出h2吗 这是我的输入和提交按钮 <div class="input-field col s6"> <i class="material-icons prefix">perm_identity</i> <input placeholder="..." id="nameClient" name="nameClient" type="text" class="validate"&g
<div class="input-field col s6">
<i class="material-icons prefix">perm_identity</i>
<input placeholder="..." id="nameClient" name="nameClient" type="text" class="validate">
<label for="nameClient">Nome do cliente:</label>
</div>
<button class="btn waves-effect waves-light indigo" id="publish-sell" type="submit"><i class="material-icons left">attach_money</i>EFETUAR VENDA</button>
这段代码的目的是将其引入ajax的完整函数中
$(document).ready(function () {
$('#draft-sell').click(function () {
var payload = {
nameClient: $('#nameClient').val(),
nameFantasySell: $('#nameFantasySell').val(),
addresOfClientSell: $('#addresOfClientSell').val(),
annotations: $('#annotations').val(),
neighborhood: $('#neighborhood').val(),
cep: $('#cep').val(),
phoneLandline: $('#phoneLandline').val(),
cellphone: $('#cellphone').val(),
autocompleteBusinessReseller: $('#autocompleteBusinessReseller').val(),
amountProduct: $('#amountProduct').val(),
productSoldSell: $('#productSoldSell').val(),
producFinalPrice: $('#producFinalPrice').val(),
registeredDaySell: $('#registeredDaySell').val()
};
$.ajax({
url: "/product/sell-draft",
type: "POST",
contentType: "application/json",
processData: false,
data: JSON.stringify(payload),
complete: function (data) {
// here is the place of the code that will extract the data from the data entered in the input and write in front-end
}
});
});
});
这是我显示结果的最后一个html标记
<h2 class="left-align white-text person-name" id="nameClientReciept">
谢谢你的帮助 如果要使用带有提交按钮的表单,则需要使用表单的submit
操作,并防止默认设置
let form=document.querySelector('form');
让nameClient=document.querySelector(“#nameClient”);
让output=document.querySelector(“#output”);
form.onsubmit=函数(e){
e、 preventDefault();//停止实际发生的提交
log(“客户端名称:”,nameClient.value);
output.innerText=nameClient.value;
}
perm_恒等式
客户名称:
随附(货币基金票据)
如果要使用带有提交按钮的表单,则需要使用表单的submit
操作,并防止默认设置
let form=document.querySelector('form');
让nameClient=document.querySelector(“#nameClient”);
让output=document.querySelector(“#output”);
form.onsubmit=函数(e){
e、 preventDefault();//停止实际发生的提交
log(“客户端名称:”,nameClient.value);
output.innerText=nameClient.value;
}
perm_恒等式
客户名称:
随附(货币基金票据)
提交后,您将打开一个新页面@ivan.rosina我希望结果通过脚本显示在页面上,脚本将以H2形式写入发送的信息,我理解,但在这种情况下,提交后必须先删除提交按钮,然后才能打开新页面@ivan.rosina我希望通过脚本将结果显示在页面上,脚本将以h2I理解的形式写入发送的信息,但在这种情况下,您首先必须删除提交按钮
<h2 class="left-align white-text person-name" id="nameClientReciept">