[英]How to create elements such as text within a div from the data entered a html form including an uploaded image?
I want the elements within a div to be created using a html form. 我希望使用HTML表单在div中创建元素。 The user will fill out a title, select an amount to spend and upload an image.
用户将填写标题,选择要花费的金额并上传图片。 On click the form's submit button I want these entered details to become the elements within the offer_display div.
在单击表单的提交按钮时,我希望这些输入的详细信息成为offer_display div中的元素。 The form and the offer_display div are on the same page.
表单和offer_display div位于同一页面上。 I want to create a javascript function that pushes this info or stores the info in a variable that can be used in the display div.
我想创建一个JavaScript函数来推送此信息或将信息存储在可在显示div中使用的变量中。
<body>
<div class="form">
Form <br><br>
<form name="input" action="javascript:alert(titleValue);">
Title: <input type="text" name="title" class="titleInsert">
<input type="submit" value="Submit">
</form>
</div>
<div class="offer_display">
<div class="title" id= title></div>
</div>
</body>
<script>
var titleValue="";
$('#titleInsert').on("change", function () {
titleValue=$(this).val();
$("#title h3").text("titleValue");
});
</script>
</html>
Use jQuery and give id
to the fields and form elements. 使用jQuery并将
id
赋予字段和表单元素。 then capture and store the values in a variable using selectors onchange
then u can use it anywhere you want. 然后使用选择器
onchange
捕获值并将其存储在变量中,然后您可以在任何需要的地方使用它。
var titleValue="";
$('#titleId').on("change", function () {
titleValue=$(this).val();
});
Enjoy :) 请享用 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.