我想知道如何在php類中插入或使用javascript或jquery。在這段代碼中,我希望每次用戶單擊添加按鈕時都會顯示一條警告,如果輸入框中沒有數字,那麼我想在數字爲零時顯示警報。我想在執行前顯示警報。如何在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();
?>
它與從php輸出html相同。而不是'回聲'
東西
''你做'回聲'';' –你使用模板嗎? – Gerep
nope我沒有使用模板 – user1645961