我在我的网站上使用PHP,Smarty,jQuery等。现在场景在一个模板文件中,有一些代码包含循环,复选框,文本字段等。供您参考我从smarty模板中输入必要的代码片段如下:
{foreach from=$subject_topic_data.topics item=topic_diff_level_data}
<input type="hidden" name="subject_{$subject_topic_data.subject_id}_topics[]" value="{$topic_diff_level_data.topic_id}">
<tr>
<td valign="middle">
<p class="custom-form">
<input type="checkbox" class="custom-check" name="{$sheet_type}_topics_{$subject_topic_data.subject_id}[]" id="{$sheet_type}_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}" value="{$topic_diff_level_data.topic_id}" {if in_array($topic_diff_level_data.topic_id, $practice_sheet_set_details[$subject_topic_data.subject_id].topics)}checked="checked"{/if}>
<label>{$topic_diff_level_data.topic_name}</label>
<!-- <input type="hidden" name="topic_names[{$topic_diff_level_data.topic_id}]" value="{$topic_diff_level_data.topic_name}"> -->
</p>
</td>
{foreach from=$topic_diff_level_data.difficulty_level item=diff_level key=key_diff_lvl}
<td valign="middle">
{if $site_id=='ENTPRM'}<em>Total {$diff_level.question_count}</em>{/if}
<input type="text" name="{$sheet_type}_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}_{$key_diff_lvl}" id="{$sheet_type}_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}_{$key_diff_lvl}" maxlength="3" class="mini" value="{$diff_level.added_no_questions}">
<input type="hidden" name="{$sheet_type}_available_questions_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}_{$key_diff_lvl}" value="{$diff_level.question_count}">
</td>
{/foreach}
</tr>
{/foreach}
现在从上面的代码中我想要实现的是当用户选中主题的复选框时,应该启用相关主题文本字段。最初,当页面加载时,应禁用所有主题的所有tesxtfields。你能帮助我实现这个目标吗?如果您想要一些额外的信息,我可以为您提供相同的信息。提前谢谢。
答案 0 :(得分:0)
客户端:
{foreach from=$subject_topic_data.topics item=topic_diff_level_data}
<input type="hidden"
name="subject_{$subject_topic_data.subject_id}_topics[]"
value="{$topic_diff_level_data.topic_id}">
<tr>
<td valign="middle">
<p class="custom-form">
复选框:提供subject_selected
<input type="checkbox" class="custom-check"
name="{$sheet_type}_topics_{$subject_topic_data.subject_id}[]"
id="{$sheet_type}_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}"
value="{$topic_diff_level_data.topic_id}"
{if in_array($topic_diff_level_data.topic_id,
$practice_sheet_set_details[$subject_topic_data.subject_id].topics)}checked="checked"{/if}>
//disabled
<label>{$topic_diff_level_data.topic_name}</label>
<!-- <input type="hidden"
name="topic_names[{$topic_diff_level_data.topic_id}]"
value="{$topic_diff_level_data.topic_name}">
-->
</p>
</td>
{foreach from=$topic_diff_level_data.difficulty_level item=diff_level key=key_diff_lvl}
<td valign="middle">
{if $site_id=='ENTPRM'}<em>Total {$diff_level.question_count}</em>{/if}
<input type="text"
name="{$sheet_type}_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}_{$key_diff_lvl}"
id="{$sheet_type}_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}_{$key_diff_lvl}"
maxlength="3" class="mini" value="{$diff_level.added_no_questions}">
<input type="hidden"
name="{$sheet_type}_available_questions_{$subject_topic_data.subject_id}_{$topic_diff_level_data.topic_id}_{$key_diff_lvl}"
value="{$diff_level.question_count}">
</td>
{/foreach}
</tr>
{/foreach}
<强>使用Javascript:强>
<script type=text/javascript>
function subject_selection(/* pass the selection here */){
var check= document.getElementById('subject_selection');
if (check.checked){
/ *如果选中,ajax?改变html值(即隐藏)?这取决于你 / 或强> document.getElementById('inputSelected')。type =“”/ 相应更改* /
}
}