javascript - 如果 CMS 的复选框为 true,则切换文本框

标签 javascript html

我尝试做类似的事情,并在我的 CMS 中实现它:

修复了 CMS 部分:

<div class="RadioList" id="radioListId">
    <div class="TxtLbl" id="textLblId"> Question </div>
    <span id="spanId">
        <input value="yes"></input>
        <input value="no"></input>
    </span>
</div>

<div class="TxtBox" id="txtBoxId">
some text
</div>

自己的 JS 部分如下:

function EnableTextbox(radioListId,spanId)
{
    if(document.getElementById(radioListId).inputValue == "yes")
        document.getElementById(textBoxId).visibility = visible;
    else
        document.getElementById(textBoxId).visibility = hidden;
}

但是我不太确定如何正确表达——我对js的理解还不够高。 非常感谢任何有帮助的评论!

最佳答案

试试这个

HTML

<div class="RadioList" id="radioListId">
    <div class="TxtLbl" id="textLblId">Question</div> <span id="spanId">
        <input type="radio" value="yes" name="showhide"> Show</input>
        <input type="radio" value="no" name="showhide"> Hide</input>
    </span>
</div>
<div class="TxtBox" id="txtBoxId">some text</div>

脚本

$(document).ready(function () {
    $("#txtBoxId").hide();
    $("input[name='showhide']").on("click", function () {
        var option = $(this).attr('value');
        if (option == "yes") {
            $("#txtBoxId").show();
        } else {
            $("#txtBoxId").hide();
        }
    });
});

Fiddle Sample

关于javascript - 如果 CMS 的复选框为 true,则切换文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26232752/

相关文章:

javascript - Node.js 中使用 setImmediate() 和 process.nextTick() 的意义

javascript - .getJSON() 中的 jQuery text()

html - 为什么在响应式网页设计中使用 HTML5?

javascript - 将 HTML 表的每一行放入不同的数组中

javascript - 在 redux 中使用生命周期方法与在 render 方法中检查 prop 状态

javascript - jQuery 上带有可折叠子菜单的菜单

javascript - Mocha before 在 It block 之后执行

javascript - 读取 iframe 内容 html

html - 是否可以为 html 电子邮件创建垂直文本方向?

html - 使用右对齐的 Bootstrap 字形图标时的内联下拉菜单 <li>