Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在提交表单之前显示表单中输入的数据_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 在提交表单之前显示表单中输入的数据

Javascript 在提交表单之前显示表单中输入的数据,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个表单,其中用户需要输入多个输入,但在提交表单之前,我希望向用户显示其i/p的显示方式 我的页面分为两部分,一部分包含表单,另一部分包含布局 <form class="form-horizontal" enctype="multipart/form-data" role="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST"> <div cl

我有一个表单,其中用户需要输入多个输入,但在提交表单之前,我希望向用户显示其i/p的显示方式

我的页面分为两部分,一部分包含表单,另一部分包含布局

<form class="form-horizontal"  enctype="multipart/form-data" role="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
    <div class="form-group">
        <label for="input01" class="col-sm-2 control-label">First Name</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="firstname" id="input01">
            </div>
    </div>

    <div class="form-group">
        <label for="input01" class="col-sm-2 control-label">Last Name</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="lastname" id="input02">
            </div>
    </div>

    <div class="form-group">
        <label for="input01" class="col-sm-2 control-label">Location</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="location" id="input03">
            </div>
    </div>
</form>

您可以将特殊的
数据
-属性添加到您的
输入
,以明确输入的文本应放在哪里。您可以随意调用它,前缀为
data-
,我们称它为
数据视图id
。然后将此属性添加到
输入中

 <input type="text" class="form-control" name="location" id="input01" data-view-id="#location">
更进一步-如果要放置文本的div的id与输入的
名称
相同-则您甚至不需要
数据
-属性:

$( "input" )
  .keyup(function() {
      var value = $( this ).val(),
          dataViewId = $( this ).attr( "name" );  // get your value using `name`
      // use this value as a selector:
      $( "#" + dataViewId ).text( value );
  })
  .keyup();

顺便说一下-
id
属性在页面上应该是唯一的。因此,拥有多个元素具有与当前相同的
id
,这是非法的。

它只显示一个条目的i/p,您能提供第一个条目使用的小提琴吗,bcoz每个div的id将不同您是否为所有输入字段添加了
数据
-属性?上面的代码很好,但是如果您的输入是数组,您需要在提交前将数组输入值存储在某个变量或数组中,并以良好的格式显示在第二页中。请帮助我
 <input type="text" class="form-control" name="location" id="input01" data-view-id="#location">
$( "input" )
  .keyup(function() {
      var value = $( this ).val(),
          dataViewId = $( this ).data( "view-id" );  // get your data-attribute value
      // use this value as a selector:
      $( dataViewId ).text( value );
  })
  .keyup();
$( "input" )
  .keyup(function() {
      var value = $( this ).val(),
          dataViewId = $( this ).attr( "name" );  // get your value using `name`
      // use this value as a selector:
      $( "#" + dataViewId ).text( value );
  })
  .keyup();