如何使用jQuery使输入的变化值成为php变量? [英] How to use jQuery to make an input's changing value a php variable?

查看:76
本文介绍了如何使用jQuery使输入的变化值成为php变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery或任何其他语言在不保存或刷新页面的情况下使输入值成为php变量?

Is it possible using jQuery, or any other language, to make an input's value a php variable without saving or refreshing the page?

我正在尝试构建一个简单的数学形式,该形式具有一个常数和一个变量.我需要显示计算出的值,类似于使用jQuery的实时预览脚本.

I am trying to build a simple math form that has one constant and one variable. I need the calculated value to be displayed similar to the Live Preview with jQuery script.

<input type="text" name="word" value="<?php $second_number ?>" />
<?php 
$first_number = 10;
$sum_total = $first_number + $second_number;
print ($sum_total); ?>

带有jQuery代码段的实时预览,供参考:

Live Preview with jQuery snippet, for reference:

<script type="text/javascript">
$(function() 
{
$(".word").keyup(function() 
{
var word=$(this).val();
$(".word_preview").html(word);
return false;
});
});
</script>

推荐答案

不,不是.

PHP是预处理器:它的输出是在您的Web浏览器上运行的HTML和Javascript.在到达浏览器时,PHP逻辑已经早已消失.

PHP is a pre-processor: its output is the HTML and Javascript that runs on your web browser. The PHP logic has long gone by the time it reaches the browser.

如果要向PHP脚本提供数据并从中取回数据(以供在网络上使用),则必须通过HTTP请求来完成此操作.

If you want to provide data to a PHP script and get data back out of it (for use on the web), you must do this through an HTTP request.

根据需要将其内联(XmlHttpRequest或"AJAX").

Make it an inline one (XmlHttpRequest or "AJAX") if you wish.

这篇关于如何使用jQuery使输入的变化值成为php变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆