javascript - 基于复选框显示隐藏表行

标签 javascript jquery html

在此Fiddle我正在尝试显示/隐藏包含基于复选框选择的文件输入的表行。但 showHide 函数没有被调用。

<div align="center" class="divBody">
<br />
<div id="controlHost">
    <div id="outerPanel">
        <table width="100%" cellpadding="2" cellspacing="5">
            <tr align="left">
                <td colspan="2">
                    <input type="checkbox" id="c1" onclick="showHide()">only Textbox</input>
                </td>
            </tr>
            <tr align="left" id="fileLabel">
                <td colspan="2">
                    <span class="message" >Select file</span>
                </td>
            </tr>
            <tr align="left" id="fileBox">
                <td valign="top" style="height:100%; width:70%;">
                    <input type="file" id="FileInput" multiple="false" class="fileInput" style="height:100%; width:100%;"/>
                </td>
            </tr>
         <tr align="left">
                <td colspan="2">
                    <span class="message" >Types</span>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" id="txtTypes" tabindex="0" style="margin-left:1px;width:100%" maxlength="50" >
                </td>
            </tr>
            <tr>
                <td align="center">
                    <input type="button" id="upload" name="Upload" value="Update" onclick="startUpload('FileInput', 1048576, 'uploadProgress', 'statusMessage', 'upload', 'cancel');"
                        class="button" />
                    <input type="button" id="cancel" name="Cancel" value="Cancel" disabled="disabled"
                        onclick="cancelUpload();" class="button" />
                </td>
            </tr>
        </table>
    </div>
</div>

最佳答案

从代码本身来看,很明显您缺少 jQuery 库(在 fiddle 中,我没有看到包含该库)。

document.getElementById('fileLabel').show();

在 jQuery 中你可以将其简化为

$('#fileLabel').show();

.show()/.hide() 是 jQuery 方法。

喜欢

$(document).ready(function () {
    $('#c1').on('change', function(){
        if ($(this).prop('checked')) {
            $('#filelabel').show();
            $('#fileBox').show();
        }
        else {
            $('#filelabel').hide();
            $('#fileBox').hide();
        }
    });
});

关于javascript - 基于复选框显示隐藏表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20094162/

相关文章:

html - 给元素一个不同于盒子的结构,例如一个三 Angular 形

javascript - 回调函数未被调用

javascript - 辅助功能:aria-haspopup 可以用来做什么?

javascript - 有没有办法在IE中的输入框中获取所选文本的偏移量?

javascript - 如何在单击上下文菜单中的选项时显示模式对话框?

javascript - 使用 jQuery 复制字段

javascript - 在 Firebase 中关联多个帐户

jquery - 在 jQuery 中委托(delegate)就绪事件

如果不适合窗口/父级大小,则 CSS 分三部分换行

html - 当图像位于 CSS 而不是 HTML 中时,如何使图像响应?