简体   繁体   English

如何制作一个活跃的网页

[英]How make a active WebPage

I have a text box in a webpage and i want when the user type something in it, display it with no refresh. 我在网页中有一个文本框,我希望当用户在其中键入内容时,不刷新就显示它。

My php file that get data from user and display it: 我的php文件从用户获取数据并显示它:

<?php 
    $text = $_GET['text'];
    echo $text;
?>

and the html file: 和html文件:

<form method="Get">
    <input type="text" name="text">
</form>

How can make it type $text when the user type in input. 用户输入时如何使它键入$ text

What is the point use PHP and AJAX in this case? 在这种情况下,使用PHP和AJAX有什么意义? If you don't store any data from user type in database, I can not see the shuffle. 如果您没有在数据库中存储来自用户类型的任何数据,则看不到随机播放。

You can use simple JavaScript function to read a value of input and set it as innerHTML of any element. 您可以使用简单的JavaScript函数读取input的值并将其设置为任何元素的innerHTML

Look on this JavaScript: 看一下这个JavaScript:

document.querySelector('input[name="text"]').addEventListener('keyup', function(e){
  const input = e.target;
  document.querySelector('#result').innerHTML = input.value;
})

and this HTML structure: 和这个HTML结构:

<form method="Get">
    <input type="text" name="text">
</form>
<div id="result"></div>

In you types in input, it's automatically supplements [id="result"] with value. 在输入中,它会自动为[id =“ result”]添加值。

This is working demo : https://jsbin.com/hadevocoqo/edit?html,js,output 这是有效的演示https : //jsbin.com/hadevocoqo/edit?html,js,output

Greetings, plum! 问候,李子!

Kindly use javascript(AJAX) for this process. 请在此过程中使用javascript(AJAX)。

All you need to do is keep the php file in a separate file and use AJAX to connect it. 您需要做的就是将php文件保存在一个单独的文件中,并使用AJAX进行连接。

<form method="Get">
<input type="text" name="text" onKeyUp="makeAjaxCall()" id="input">
    </form>



<script>
function makeAjaxCall() {
let input = document.getElementById('input').value;
if(input){
// make the ajax function call here
// Ajax response is injected into the document using innerHTML.
connectViaAJAX();
} else {
// no input is provided.
}
}



function connectViaAJAX() {
// write ajax here
}
</script>

There are other javascript libraries out there that you can check out Angular: http://angular.io/ 您还可以查看Angular的其他JavaScript库: http : //angular.io/

VueJs: https://vuejs.org/ VueJs: https ://vuejs.org/

ReactJs: https://reactjs.org/ ReactJs: https ://reactjs.org/

and many more. 还有很多。

You can visit : https://w3schools.com for more programming tutorials 您可以访问: https : //w3schools.com以获得更多编程教程

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

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