javascript 如何在同一页面回显输入值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14546219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:55:45  来源:igfitidea点击:

How echo input value in same page?

phpjavascripthtml

提问by Sudha Sarath

Have a coding:

有一个编码:

if(!$fgmembersite->CheckLogin())
{ $loggedin="0";} else { $loggedin="1"; }
if ($loggedin=="1") { echo "<form method=\"post\">
<input type=text id=\"nameField\" name=\"nameField\" value=\"". $fgmembersite->UserFullName() ." \"/></form>"; }

Want to echo again the nameField likE:

想再次回显 nameField likeE:

<?php echo $nameField ?>

How is this possible?

这怎么可能?

回答by Ondra ?i?ka

<form action="the-same-page.php">

    ... your code...

    <input type="submit">
</form>

<?php echo $_POST['nameField'] ?>

If you need it without submit, then it's client-side only action.

如果您不需要提交就需要它,那么它只是客户端的操作。

<input type="text" id="foo" 
   onchange="document.getElementById('output').innerHTML = this.value"/>

<div id="output">output will be here</div>

回答by Stuart Elliot

<? echo $_POST['nameField']; ?>

This is echo Posted Value...

这是回声贴值...

回答by vlcekmi3

Without resfreshing the page / submitting the form you need to use javascript.

在不刷新页面/提交表单的情况下,您需要使用 javascript。

Include jquery then you can do something like this

包括 jquery 然后你可以做这样的事情

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
$(document).ready(function(){
    jQuery("#nameField").keyup(function () {
        var value = $(this).val();
        $("#xx").text(value);
    });
});
</script>

<?php

echo '<form action="" method="post">
    <input type="text" id="nameField" name="nameField" value="'.$fgmembersite->UserFullName().'" />
</form>';

?>

<span id="xx"></span>