7

这是我的代码:http: //jsfiddle.net/Draven/rEPXM/23/

我想知道在单击图像以将输入框添加到表单Add之前如何隐藏该提交按钮。+

我不想在输入框旁边添加提交按钮,因为我希望能够添加多个输入框并在单击时将它们全部提交Add

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" />');
}​
4

4 回答 4

21

只需给按钮一个 ID,并使其开始隐藏

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

然后使用show()jQuery方法:

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

http://jsfiddle.net/TcFhy/

于 2012-10-24T14:41:56.803 回答
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);
    }
}​
于 2012-10-24T14:52:55.630 回答
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/

于 2012-10-24T14:43:53.173 回答
0
$('form#folderform input[type=submit]').hide();

然后点击提交后显示添加按钮

http://jsfiddle.net/SQh8L/

于 2012-10-24T14:40:32.710 回答