【发布时间】:2014-02-13 18:11:23
【问题描述】:
我是一名新手 PHP 开发人员。
我有一个包含 Add 按钮的 HTML 页面的 PHP Web 项目。该页面的名称是Awards.html。在其他地方,我创建了一个 PHP 类,Awards.php,其中包含一个函数。
我的文件源代码如下:
Awards.html
<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!
}
}
这里的问题是,在Add按钮的点击事件上,我需要调用Awards.php文件的clickFunction()。谁能告诉我怎么做?
我们将非常感谢您尽早回复。谢谢。
【问题讨论】:
-
PHP 是服务器端和 HTML 客户端。所以你不能直接在你的班级里直接打电话给
clickFunction。您将需要一个 Ajax 调用或将您的表单提交到另一个调用clickFucntion的 PHP 页面 -
非常感谢您的回复。您能否提供有关如何实现此功能的 AJAX 源代码以及我需要放置此代码的位置?
-
你应该能够从这个线程stackoverflow.com/questions/5004233/…提取足够的信息