让我详细解释一下问题。我正在使用PHP和Smarty。我从查询字符串中获取一个值
现在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值为back(即{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>
有人可以向我解释如何实现这个功能吗?谢谢提前。