问题描述
我是菜鸟PHP开发人员。
I am a rookie PHP developer.
我有一个包含添加骨节病>按钮HTML页的PHP Web项目。页面的名称是 Awards.html
。在其他地方我创建了一个PHP类, Awards.php
,其中包含的功能。
I have a PHP web project with an HTML page that contains an button. The name of the page is Awards.html
. Elsewhere I have created a PHP class, Awards.php
which contains a function.
我的文件源$ C $ C给出如下:
The source code of my files is given as follows:
<div class="divparent">
<div class="modal-header">
<div class="btn-group">
<button class="btn" data-bind="click: closeModal">Exit</button>
</div>
</div>
<div class="modal-title">
<h1 id="headerid">Awards</h1>
</div>
<div class="modal-body">
<input id="hdnValueCurrentAwardSoid" type="hidden" value="null" />
<div class="divleft">
<input id="txtName" maxlength="80" type="text" class="water newpost1" placeholder="Award Name" tabindex="1" />
<section class="ThumbnailContainer">
<img id="imgThumbnail" class="imgThumbnail" />
<img src="http://localhost/rockontechnologies/Images/GreenRibbon.png" id="pictureribbon" class="pictureribbon" />
<input type="text" contenteditable="false" readonly id="transformtext" />
</section>
<textarea id="txtdescription" placeholder="Description" class="water newpost1" rows="4" tabindex="2"></textarea>
<div class="ui-widget">
<input id="txtIssueOrg" maxlength="50" type="text" placeholder="Issue Organization" />
</div>
</div>
</div>
<div class = "divbottom">
<div id="divAddAward">
<button class="btn" onclick="">Add</button>
</div>
</div>
</div>
Awards.php
<?php
class Awards
{
function clickFunction()
{
//Function that needs to be executed!
}
}
这里的问题是,在单击事件的添加骨节病>按钮,我需要调用 clickFunction()
的 Awards.php
文件。谁能告诉我该怎么做呢?
The problem here is that on the click event of the button, I need to call the clickFunction()
of the Awards.php
file. Can anyone please tell me how to do this?
在最早的答复将是非常美联社preciated。谢谢你。
Replies at the earliest will be highly appreciated. Thank you.
推荐答案
您应该做这样的事情。
<button class="btn" onclick="onrequest();">Add</button>
function onrequest() {
$.post(
'example.php'
).success(function(resp){
json = $.parseJSON(resp);
alert(json);
});
}
和在使用example.php调用你的函数
and in example.php call your function
$class = new Awards();
$method = $class->clickFunction();
echo json_encode($method);
和你clickFunction();
and in your clickFunction();
clickFunction(){
$array = array(
'status' => '1'
);
return $array;
}
这篇关于如何调用PHP函数从HTML按钮点击一类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!