On Link Click Do Something and Change Text (Html, PHP, JS)
right now I'm just trying to figure out how I could do the following :
I have this t开发者_StackOverflow中文版ext right, and it says "report"
I'd like it, so when someone clicks on the report link, it simply executes some PHP code and then changes the text from "report" to "reported" and the font from red to green.
Thanks!
There are a couple options here.
The first is to do this asynchronously via an AJAX call. The text should be like this:
You can read about ajax here: Ajax Tutorial from W3Schools
Your next option is to simply have the click of the text reload the page with a query string. So you could make it an anchor like this:
<a href='yourBasePage.php?reportClicked=true'><?php echo $reportText; ?></a>
Then, in your php, use $_REQUEST['report'] to see if it's true. If it is, process the report and make $reportText 'reported'.
The first option won't work at all if the user has javascript turned off. The second has to reload the page.
Good luck!
精彩评论