为什么不能将链接切换为可见

Why cannot toggle the link to be visible?

本文关键字:不能 链接 为什么      更新时间:2023-09-26

我尝试了下面的代码,但仍然不起作用。这个想法是,一旦文件被选中,显示一个链接,允许文件被删除(或取消选中)。我想解决这个谜题,为什么链接不显示它应该。非常感谢你的帮助!

对于信息,我也尝试了"css","显示"answers"隐藏"。没有作品。
<html>
<script>
function removeFile()
{
  var input = document.getElementById("fileToUpload");
  input.value = input.defaultValue;
  refreshForm();
  return false;
}
function refreshForm() 
{
  var input = document.getElementById("fileToUpload");
  if (input.files.length > 0)
  {
    $("#upack-form > #remove-lnk").attr("visibility", "visible");
  }
  else
  {
    $("#upack-form > #remove-lnk").attr("visibility", "hidden");
  }
}
</script>
<div class="package">
  <form id="upack-form" action="/update_package" enctype="multipart/form-data" method="post">
    <label>
      <input id="fileToUpload" type="file" name="file" style="width: 280px; overflow: hidden;" single onChange="refreshForm();" />
      &nbsp;&nbsp;&nbsp;&nbsp;
    </label>
    <a id="remove-lnk" style="visibility: hidden;" onclick="return removeFile();">remove</a>
  </form>
</div>
</html>
编辑:

我发现在"标签"内移动超链接的差异。在这种情况下,它不起作用。

可见性不是一个属性,它是一个样式属性

if (input.files.length > 0)
  {
    $("#upack-form > #remove-lnk").css("visibility", "visible");
  }
  else
  {
    $("#upack-form > #remove-lnk").css("visibility", "hidden");
  }

PD:正如我在评论中告诉你的,我注意到你没有包括jQuery,所以我加入了。现在,这里是工作演示