让我详细解释一下这个问题。我正在使用 PHP 和 smarty。我op=back
从查询字符串中得到一个值。但这不会在每次 PHP 文件运行时发生,所以op=back
我必须在什么时候触发特定链接上的单击事件。我的 PHP 文件代码片段如下:
<?php
include_once("includes/teacher-application-header.php");
prepare_request();
$request = empty( $_GET ) ? $_POST : $_GET ;
$op = $request['op'];
$objTeachClassSub = new TeacherClassesSubjects();
global $teacher_profile_from_session;
$teacher_id = $teacher_profile_from_session['TEACHER_ID'];
$teacher_classes_subjects = $objTeachClassSub->GetClassSubjectMappingsbyTeacherId($teacher_id);
$smarty->assign('teacher_classes_subjects', $teacher_classes_subjects);
$smarty->assign("op",$op);
$smarty->display("teacher-details.tpl");
?>
现在 smarty 文件中的代码片段如下:
{literal}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
</script>
{/literal}
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td align="left" valign="top">
<h3>Teacher Details</h3>
</td>
</tr>
</table>
<table width="99%" border="0" cellpadding="0" cellspacing="0" class="manage_box" >
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr>
<td width="25%">
{if $teacher_classes_subjects}
{foreach from=$teacher_classes_subjects item="classes_subjects"}
<b><a href="#" id="{$classes_subjects.class_id}">{$classes_subjects.class_name}</a></b><br />
{if $classes_subjects.class_subjects}
<div id="class_subjects_{$classes_subjects.class_id}">
{foreach from=$classes_subjects.class_subjects item="class_subjects"}
<i><a id ="back" href="chapter_details.php?class_id={$classes_subjects.class_id}&cs_map_id={$class_subjects.cs_map_id}">{$class_subjects.subject_name}</a></i><br />
{/foreach}
</div>
<br />
{/if}
{/foreach}
{/if}
</td>
<td width="75%">
{if $chapter_details}
<ul>
{foreach from=$chapter_details item=chapter}
<li><a href="chapter_details.php?op=get_chapter_theory&chapter_id={$chapter.chapter_id}&class_id={$class_id}&cs_map_id={$cs_map_id}&chapter_title={$chapter.chapter_title}">{$chapter.chapter_title}</a></li>
{/foreach}
</ul>
{/if}
{include file=$file_to_show}
</td> aly what is
</tr>
</table>
</td>
<td align="left" id="subject_container" valign="top">
</td>
<td align="left" id="chapter_container" valign="top">
</td>
</tr>
</table>
现在我想要实现的是在上面的智能模板文件中编写一个 jQuery 代码,如果 op 值返回(即{op==back}
),它将执行。实际上,预期的是op=back
点击事件应该在以下链接上触发:
<a id ="back" href="chapter_details.php?class_id={$classes_subjects.class_id}&cs_map_id={$class_subjects.cs_map_id}">{$class_subjects.subject_name}</a>
谁能解释我如何实现这个功能?提前致谢。