JS is the language of the front-end, and PHP is the language of the back-end. When I first started learning, I often couldn’t distinguish between the front-end and the back-end (I was like this at the beginning, and I still do it sometimes now). My original idea was to treat the front-end and back-end as two Islands cannot be crossed. HTML is like a bridge. When you want to transfer variables from one island to another, you can only use this bridge.
Let me make a small summary:
1: How to transfer the value in HTML to JS. The following assumes that it is file 1.php
Copy code The code is as follows:
>
">
< /html>
JS If you want to get the name value entered by the user in the text box, write like this
Copy code
The code is as follows:
function get(){
var n=document.getElementById('username').value;
alert (n);
}
In this case, an alert box will pop up when JS get() is called, and the content inside is the value of name.
2: If the name value obtained in JS is to be returned to the rename text box, write like this
Copy code
The code is as follows:
In this case, calling get() below will automatically show you The value entered in name above.
3: Get the value of the page in PHP
I think everyone knows this
Copy the code The code is as follows:
$name=$_REQUEST["username"];echo $name;
?>
4: PHP value is returned to the page
Insert PHP language into HTML, you can call the value of the variable in PHP, or you can use Smarty (recommended).
With the above, whether it is the value in the HTML page or the value of the variable in JS, it can be easily passed into PHP. Of course, the value of PHP can also be passed to the desired place.
http://www.bkjia.com/PHPjc/327851.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/327851.htmlTechArticleJS is the language of the front-end, and PHP is the language of the back-end. When you first learn, it is often difficult to distinguish between the front-end and the back-end. (I was like this at the beginning, and I still do it sometimes now). My original idea was to put my ex...