0

我正在为我的网站使用 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 时,应禁用。你能帮我实现这个目标吗?如果您想要一些其他信息,我可以为您提供相同的信息。提前致谢。

4

1 回答 1

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">

复选框:给出 idsubject_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 = "" /相应地更改它 */

    }
}
于 2013-09-19T06:19:30.347 回答