我想知道如何在 php 类中插入或使用 javascript 或 jquery。在这段代码中,我想在每次用户单击添加按钮时显示一个警报,如果输入框中没有数字,那么我想在数字为零时显示一个警报我想在执行之前显示警报。
<!DOCTYPE html>
<html>
<head><title>OOP Adding Machine</title></head>
<body>
<div align="center">
<h1 style="color:#00F">Welcome User</h1>
<p style=" color:#00F; font-size:18px; font-weight:bold ">Please enter two numbers in the given input boxes, and this program will add them and display the answer.</p>
<form action="code.php" name="form1" method="post"> <br /><strong>Number#1:</strong><input type="text" name="adder1" /> <br /><strong>Number#2:</strong><input type="text" name="adder2" /><br /><input type="submit" name="submit" value="ADD"/> </form>
</div>
</body>
</html>
这是php oop代码:
<?php
class addition
{
var $adder3;
function adder($adder1,$adder2)
{
$this->adder3=$adder1+$adder2;
}
function sol()
{
echo "<h1>"." Result: ".$this->adder3."</h1>" ;
echo "<h2>"."Program Executed"."</h2>";
}
}
$result=new addition();
$result->adder($_POST['adder1'],$_POST['adder2']);
$result->sol();
?>