代码之家  ›  专栏  ›  技术社区  ›  Eric Belair

如何取消隐藏具有Ajax绑定本身的动态内容的cfdiv?

  •  1
  • Eric Belair  · 技术社区  · 16 年前

    我有以下用于填充文本输入的cfselect标记:

    <cfselect id="this" name="this" bind="cfc:Data.getThis()" bindonload="true" />
    
    <cfselect id="that" name="that" bind="cfc:Data.getThat({p1})" />
    
    <cfselect id="theOther" name="theOther" bind="cfc:Data.getTheOther({p1}, {p2})" />
    

    文本输入是唯一需要以表单形式提交的值:

    <cfform name="addItem" method="post" action="somepage.cfm">
        <cfinput 
            type="text" 
            id="item" 
            name="item" 
            bind="cfc:Data.getResult({this}, {that}, {theOther})" /><br />
    
        <cfinput 
            type="submit" 
            name="addButton" 
            value="Add Item" />
    </cfform>
    

    我想让窗体及其内容可见 只有 当所有三个选项都已做出时,文本输入有一个值。最好的方法是什么?我假设使用cfdiv是最好的方法,但我不确定如何以这种方式加载动态内容(cfinputs)。

    1 回复  |  直到 16 年前
        1
  •  2
  •   Adam Tuttle    16 年前
    <cfselect id="this" name="this" bind="cfc:Data.getThis()" bindonload="true" onChange="toggleForm();" />
    <cfselect id="that" name="that" bind="cfc:Data.getThat({p1})" onChange="toggleForm();" />
    <cfselect id="theOther" name="theOther" bind="cfc:Data.getTheOther({p1}, {p2})" onChange="toggleForm();" />
    
    <div id="theForm" style="display:none">
    <cfform name="addItem" method="post" action="somepage.cfm">
        <cfinput 
            type="text" 
            id="item" 
            name="item" 
            bind="cfc:Data.getResult({this}, {that}, {theOther})" /><br />
    
        <cfinput 
            type="submit" 
            name="addButton" 
            value="Add Item" />
    </cfform>
    </div>
    
    <script type="text/javascript">
        function toggleForm(){
            var a = document.getElementById("this").selectedIndex;
            var b = document.getElementById("that").selectedIndex;
            var c = document.getElementById("theOther").selectedIndex;
            if (a > -1 && b > -1 && c > -1){
                document.getElementById("theForm").style.display = "";
            }
        }
    </script>
    

    我个人会通过使用jquery来简化JS,但我不知道您是否已经在自己的站点上使用jquery,我不想成为另一个“使用jquery”的空答案;因此,如果没有jquery,这应该可以工作,如果您希望/需要不使用它。(但jquery太棒了!)