Has a function a ($a) {
}
echo ""
How to write??
Why can't I write it out of the execution?
Reply content:
Has a function a ($a) {
}
echo ""
How to write??
Why can't I write it out of the execution?
HTML cannot use PHP-level functions
Echo to the page is a piece of HTML text, this time input.submit triggered by a () is the JavaScript function in the page, you define in PHP a () is not called
The onclick is an event of the browser that can invoke a JS function, but cannot invoke a PHP function, because the PHP interpreter is on the server. So you can do this, after the onclick call a JS function, this JS function to the PHP server to make an AJAX request, You can then write a PHP function to respond to and return the data to the browser. AJAX operations are recommended using the $.post () and $.get () of the jquery library.
The front and rear end points are clear,
If you want the client click to invoke the Execute function,
Then the function will be written JS, the onclick inside the call JS function,
If the server is running that function, the contents of the onclick inside the page are loaded and fixed.
PHP is executed on the server side, and JavaScript is performed on the client. Although the code is written together, the execution time is different.
You can use PHP to output JavaScript in the page to assign values to the front-end variables.
You can also use JavaScript to request a URL interface to do PHP in the back-end encapsulation of the good way.
The execution order of the code is to execute PHP code on the server first, the PHP output string type of HTML code to the client, when the PHP execution can no longer execute any PHP code, and then the next thing to the browser, JS, CSS and so on to render the parsing execution ...
You can use JS in HTML to port your PHP functions, and then execute the JS function, such as:
/*HTML*/
/*JS*/function test(a){ console.log(a);}
General HTML calls the function in JS inside
If the master finishes reading the previous answer, the front-end script and the back-end script have been clarified.
So now the demand with Ajax should be able to achieve
There is no PHP code in the browser. PHP First parse the file, generate an HTML file, and then the browser to get the HTML file inside a line of PHP code is not. Of course it can't be done.
echo "";
That's how it should be written.
When the form input type is submit, click will submit this form, you can change type= ' submit ' to type= ' button '