2012-10-24 124 views
3

这里是我的代码:http://jsfiddle.net/Draven/rEPXM/23/隐藏输入按钮

我想知道我怎么可以隐藏添加提交按钮,直到我点击+图像输入框添加到窗体。

我不想在输入框旁边添加提交按钮,因为我希望能够添加多个输入框并将其全部提交,当我点击添加

HTML

<div id="left">  
    <div class="box"> 
    <div class="boxtitle"><span class="boxtitleleftgap">&nbsp;</span><span class="boxtitlebulk"><span class="boxtitletext">Folders</span><div style="float: right; margin-top: 4px;"><a href="#" onclick="javascript: AddFolder();"><div class="addplus">&nbsp;</div></a></div></span></div> 
     <div class="boxcontent"> 
     <form method="post" id="folderform" action="page.php?action=list-volunteer-apps" name="folderform"> 
      <a class="even" href="page.php?action=list-volunteer-apps&folder=2">Folder 2 <span class="text">(1)</span></a><a class="even" href="page.php?action=list-volunteer-apps&folder=1">Folder 1 <span class="text">(0)</span></a> 
      <div id="foldercontainer"><input type="submit" value="Add"></div> 
     </form> 
     </div> 
    </div> 
</div> 

jQuery的

function AddFolder() { 
    $('#foldercontainer').append('<input name="folder[]" type="text" size="20" />'); 
}​ 

回答

14

只要给该按钮的ID,并使其开始隐藏

<input type="submit" id="addButton" value="Add" style="display: none;"> 

然后使用show() jQuery的方法:

$("#addButton").show(); 

http://jsfiddle.net/TcFhy/

1

我感动的按钮出来的文件夹换行,并且我在添加新文件夹时显示它。通过这种方式,添加新文件夹时按钮将保持在最底部。我还删除了内联样式,并将其替换为一个类。

这是用来显示按钮,只需将其添加到AddFolder()功能:

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

我用CSS隐藏这样的:

#addBtn { display: none;} 

我感动按钮出来的#foldercontainer,这样当你添加多个文件夹时,它会一直停留在最下面,如你所愿:

<div id="foldercontainer"></div> 
<input id="addBtn" type="submit" value="Add"> 

在这里寻找jsFiddle:http://jsfiddle.net/kmx4Y/1/

2

这里有一种方法可以做到这一点......同时,清理用于制作这些输入框位的方法:

http://jsfiddle.net/mori57/4JANS/

所以,在你的HTML,你可能有:

<div id="foldercontainer"> 
     <input id="addSubmit" type="submit" value="Add"> 
     <input id="folderName" name="folder[]" type="text" size="20" style="" /> 
    </div> 

和你的CSS可能是:

#foldercontainer #addSubmit { 
    display:none; 
} 
#foldercontainer #folderName { 
    display:none; 
    width: 120px; 
    background: #FFF url(http://oi47.tinypic.com/2r2lqp2.jpg) repeat-x top left; 
    color: #000; 
    border: 1px solid #cdc2ab; 
    padding: 2px; 
    margin: 0px; 
    vertical-align: middle; 
} 

和您的脚本可能是:

// set up a variable to test if the add area is visible 
// and another to keep count of the add-folder text boxes 
var is_vis = false, 
    folderAddCt = 0; 

function AddFolder() { 
    if(is_vis == false){ 
     // if it's not visible, show the input boxes and 
     $('#foldercontainer input').show(); 
     // set the flag true 
     is_vis = true; 
    } else { 
     // if visible, create a clone of the first add-folder 
     // text box with the .clone() method 
     $folderTB = $("#folderName").clone(); 
     // give it a unique ID 
     $folderTB.attr("id","folderName_" + folderAddCt++); 
     // and append it to the container 
     $("#foldercontainer").append($folderTB); 
    } 
}​