您可以使用$.ajax()
将值传递给 PHP:
http ://api.jquery.com/jQuery.ajax/
<script>
$(document).ready(function(){
$('a').click(function(){
var title = $(this).attr('value');
$('.div').attr('value', title);
//Communicate with file.php pass it the title via POST
//If the php returns a true or a json value, alert it.
//Otherwise if php returns false or an http error code, alert there was an error.
$.ajax({
url: "/path/to/file.php",
data: { "title": title },
type: "POST",
dataType: "JSON",
success: function(d){
alert("The Call was a success: "" + d);
},
error: function(d){
alert("There was an error, it was: " + d);
}
});
//Make sure you do this, otherwise the link will actually click through.
return false;
});
});
</script>