![](/img/trans.png)
[英]How to call php function "oninput" just like javascript function is called?
[英]Using oninput function with php?
据我oninput
,HTML 中的oninput
函数总是与 Javascript 一起使用。 是否可以将 PHP 添加到其中?
<input name="boxNo" type="number" value="1" oninput="<?php $intro = $intro . "boxNo.value"?>"/>
如果可能,我应该如何构建我的代码?
当然,您不能直接从 html 调用 php,如您的示例所示。 但是您可以使用 AJAX 来做到这一点,使用放置在您服务器上的 JS、jQuery 和 PHP 脚本。
例如:
JavaScript:
$('input[name=boxNo]').input(function(){
var inputObject = $(this);
var value = inputObject.val();
$.post('/yourfileOnServer.php', {value: value}, function(data){
//in the variable data you've already got your info from the php
inputObject.val(data); //inserting data to the value of your input
});
});
PHP:
if(!isset($_POST['value'] || empty($_POST['value'])){
exit; //Avoiding security problems
}
$value = $_POST['value']; //In this variable you store your value, entered to the input
// DO something with this value
echo $value; //and print it (return to the JS)
祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.