简体   繁体   English

div中的文本从表单获取输入

[英]Text in div gets input from the form

following is my div and i want to know how can i get the input from the form lets say from textfield 'name' and display that input name instead of jhon in the following div, Kindly help!! 以下是我的div,我想知道如何从表单中获取输入内容,让我们从textfield'name'说出来,并在接下来的div中显示该输入名称而不是jhon,请帮助!

<div id='faix' class="bg4 w460 h430 tac poa dpn ">
                    <h4 class="fwb fs22 cf3 mb5 ff3 mt150 ">Thank you John for contacting us!</h4><h4 class="fwb fs22 cf3 mb5 ff3"> We will get in touch with you shortly.</h4>
                </div>

See http://jsfiddle.net/wfAgb/ 参见http://jsfiddle.net/wfAgb/

//get the name
var Name = $('#name').val();
//replace John with the new name
$('.mt150').text($('.mt150').text().replace('John', Name));

You could with great benefit make span arounde the name so you can change it directly. 您可以极大地受益于该名称,因此可以直接更改它。

<h4 class="fwb fs22 cf3 mb5 ff3 mt150 ">Thank you <span id="formName">John</span> for contacting us!</h4>

And then do 然后做

var Name = $('#name').val();
$('#formName').text(Name);

html: 的HTML:

<form id="myForm">
  <input id="name" name="name" value=""/>
</form> 

js: js:

$("#myForm").submit(function(){
  $("#faix h4.mt150").empty().append("Thank you "+$("#name").val()+" for contacting us!");
    return false;
})​

demo : http://jsfiddle.net/BPXpb/1/ 演示: http : //jsfiddle.net/BPXpb/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM