我正在使用smarty模板,我的代码如下:
<div class="breadcrumb-wrap">
{include file='resources-sub-menu.tpl'}
<ul class="page-flow">
<li><a href="#">Home</a><span>></span></li>
<li>Questions</li>
</ul>
</div>
<h1 class="c-heading"> Match Questions </h1>
<div class="c-grad-box fnShowData">
<div class="form-wrapper">
<form id="view-questions-form" name="questions_filter" action="{$control_url}modules/questions/match_question.php" method="post">
<input type="hidden" name="page" id="page" value="1" >
<div class="w50">
<ul>
<li>
<label>Subjects</label>
<div class="form-element">
<select name="subject_id" id="subject_id" onchange="get_topics_by_subject(this.value, 'get_topics_by_subject_for_filter', '#topic_id'); return false;">
<option value="">All</option>
{foreach from=$all_subjects item=subjects key=key}
<option value="{$subjects.subject_id}" {if $subject_id == $subjects.subject_id} selected="selected"{/if}>{$subjects.subject_name}</option>
{/foreach}
</select>
</div>
</li>
</ul>
</div>
<div class="w50">
<ul>
<li>
<label>Topics</label>
<div class="form-element">
<select name="topic_id" id="topic_id">
<option value="">All</option>
{foreach from=$all_topics item=topics key=key}
<option value="{$topics.topic_id}" {if $topic_id==$topics.topic_id} selected="selected"{/if}>{$topics.topic_name}</option>
{/foreach}
</select>
</div>
</li>
<li>
<div class="find-que-ans">
<p class="custom-form"><label></label></p>
<input type="submit" class="c-btn submit_form" name="btn_submit" id="btn_submit" value="Match Questions" />
</div>
</li>
</ul>
</div>
</form>
</div>
</div>
<br/><br/>
<table width="100%" class="base-table tbl-practice" cellspacing="0" cellpadding="0" border="0">
<tr class="evenRow">
<th width="33%" style="text-align:center;" class="question-id">Que ID</th>
<th width="33%" style="text-align:center;" class="question-id">Matching Que IDs</th>
<th width="33%" style="text-align:center;" class="question-id">Percentage(%)</th>
</tr>
{if $all_match_questions}
{foreach from=$all_match_questions item=qstn key=key}
{if $qstn.similar_questions_ids_and_percentage}
<tr class="oddRow">
<td class="question-id" align="center" valign="top">
<a href="{$qstn.return_url}" title="View question" class="inline_view_question_detail">QUE{$qstn.question_id}</a>{if $qstn.question_appeared_count gt 1}-Appeared({$qstn.question_appeared_count}){/if}
</td>
<td class="question" align="center" valign="top">
{foreach from=$qstn.similar_questions_ids_and_percentage item=question key=q_no}
{if $question.question_id!=''}
<a href="{$qstn.return_url}" title="View question" class="inline_view_question_detail">QUE{$question.question_id}</a>{if $question.question_appeared_count gt 1}-Appeared({$question.question_appeared_count}){/if}
{if $question.question_appeared_count eq 0}
<a href="{$control_url}modules/questions/match_question.php?op=delete&question_id={$question.question_id}&subject_id=&topic_id=" title="Delete question" class="inline_view_question_detail"> Delete</a>
{/if}
{/if}<br />
{/foreach}
</td>
<td class="question" align="center" valign="top">
{foreach from=$qstn.similar_questions_ids_and_percentage item=question key=q_no}
{if $question.percentage!=''}{$question.percentage}{/if}<br />
{/foreach}
</td>
</tr>
{/if}
{/foreach}
{else}
<tr>
<td colspan="2" align="center"><b>No Questions Available</b></td>
</tr>
{/if}
</table>
您可以从上面的代码中观察到,分别有两个名为subject_id和topic_id的隐藏字段。 现在,在单击超链接时,我想在查询字符串中发送这些隐藏的值。以下是我想要将subject_id和topic_id附加到当前查询字符串的超链接的当前代码。任何人都可以指导我吗?
<a href="{$control_url}modules/questions/match_question.php?op=delete&question_id={$question.question_id}&subject_id=&topic_id=" title="Delete question" class="inline_view_question_detail"> Delete</a>
此处需要注意的另一件事是我不想提交表格。我只想通过查询字符串发送值。
答案 0 :(得分:1)
隐藏字段的工作方式与任何其他输入一样,该值将来自输入框的名称。
<a href="{$control_url}modules/questions/match_question.php?op=delete&question_id={$question.question_id}&subject_id={$subjects.subject_id}&topic_id={$topics.topic_id}" title="Delete question" class="inline_view_question_detail"> Delete</a>
答案 1 :(得分:1)
为什么你使用隐藏字段而不选择值? 在这种情况下,找到选择值,因为这是主题id
on click for anchor tag
var id=$("#subject_id").val();//find select value
var subjectid=$("#"+id).val();
//Append in anchor tag href and similarly for topic id
答案 2 :(得分:0)
查看您的代码,在我看来,“subject_id”和“topic_id”都是字符串。
如果它们是字符串只是基本附加它们很容易。但如果没有,而且它是一个变量,就像下面的回声一样
<select id= "<? subject_id ?>">
答案 3 :(得分:0)
如果要在加载页面时访问theese两个字段的值,可以使用:
$('#subject_id').val()
$('#topic_id').val()
如果在表单呈现后选择其他值,则应使用javascript并将链接的单击绑定到javsacript函数:
$('.inline_view_question_detail').on('click', function() {
var data = {}
data['op'] = 'op';
data[question_id'] = 'idofquestion';
//and put your variables here
$.ajax({
url: 'theurltowhichyouwanttosendthedata',
type: "POST",
data: data,
success: function() {
alert('success');
}
});
});