在javascript函数中调用PHP函数 [英] Calling a PHP function in javascript function
问题描述
一个简单的问题,通过按钮通过onclick调用javascript函数..
并且js函数调用php函数..
我的实际座右铭是,当点击一个html按钮时应该调用一个函数。所以该函数应该能够阻止一个div。
快速回复将帮助我alotttt
我尝试过:
A simple problem where a javascript function is being called by button through onclick..
And that js function calls a php function..
My actual motto is that a function should be called when a html button is clicked..so that the function should be able to block a div.
Quick reply will help me alotttt
What I have tried:
<?php
function f1()
{
echo "f1 called";
}
function f2()
{
echo "f2 called";
}
?>
<html>
<head><title>Trail</title></head>
<body background="yellow" onload="start()">
<div style="display:none" id="1">
<h1>SYSTEM</h1>
</div>
<div style="display:none" id="2">
<p>Welcome</p>
</div>
<div style="display:none" id="3">
<p>Ramaa</p>
</div>
<input type="button" value="welcome" onclick="one()">
<input type="button" value="welcome" onclick="two()">
<script>
function start()
{
document.getElementById("1").style.display="block";
}
function one()
{
document.getElementById("2").style.display="block";
document.getElementById("3").style.display="none";
<?php
f1();
?>
}
function two()
{
document.getElementById("2").style.display="none"
document.getElementById("3").style.display="block";
<?php
f2();
?>
}
</script>
</html>
//问题
在插入php代码之前它工作得非常好,即onload正常工作并且点击按钮相应的功能被调用。但是当我放入它中的php代码..onload无法正常工作,onclick也无法正常工作。如果有人让我知道其中的错误,将会非常有帮助。
//problem
Before inserting php code it worked really great i.e, onload is working and onclicking buttons corresponding functions are called.But when I put php code in it..onload is not working and onclick is also not working.It will be very helpful if someone let me know the mistake in it.
推荐答案
a非常简单的测试,希望它能让你前进
index.php
a very simple test for you, hope it will get you going
index.php
<HTML>
<HEAD>
<SCRIPT SRC="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></SCRIPT>
<SCRIPT>
function call_function (value) {
var a = document.forms[0].a.value;
var b = document.forms[0].b.value;
.get({
url:'func.php?a ='+ a + '& b ='+ b +& action =+ value,
success:function(result){
.get({ url: 'func.php?a=' + a + '&b=' + b+"&action="+value, success: function(result){
('#here')。html(result) ;
}
}
);
返回false;
}
< / SCRIPT>
< / HEAD>
< BODY>
< FORM onsubmit ='return false'>
< INPUT NAME = a> <峰; br>
< INPUT NAME = b> <峰; br>
< INPUT TYPE = SUBMIT VALUE = add NAME = action onclick =call_function(this.value)>
< INPUT TYPE = SUBMIT VALUE =乘以NAME = action onclick =call_function(this.value)>
< FORM>
< div id ='here'>
< / div>
< / BODY>
< / HTML>
('#here').html(result); } } ); return false; } </SCRIPT> </HEAD> <BODY> <FORM onsubmit='return false'> <INPUT NAME=a> <br> <INPUT NAME=b> <br> <INPUT TYPE=SUBMIT VALUE=add NAME=action onclick="call_function(this.value)"> <INPUT TYPE=SUBMIT VALUE=multiply NAME=action onclick="call_function(this.value)"> <FORM> <div id='here'> </div> </BODY> </HTML>
func.php
func.php
<?php
function add(
这篇关于在javascript函数中调用PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!