n00*_*101 8 php variables jquery element
基本上,我有一个清单:
<li class="list">fruit</li>
<li class="list">vegetables</li>
<li class="list">protein</li>
Run Code Online (Sandbox Code Playgroud)
而且,我想找到最后一个列表项,从中获取文本,然后将其分配给php变量,以便:
<?php
$variable = 'protein';
?>
Run Code Online (Sandbox Code Playgroud)
我对如何将它变成php变量很模糊?
Sam*_*son 21
$.post("script.php", { value: $(".list:last").text() }, function (result) {
alert(result); // alerts whatever comes from the php script
});
Run Code Online (Sandbox Code Playgroud)
print strtoupper( $_POST["value"] );
Run Code Online (Sandbox Code Playgroud)