我有一个连接到 jQuery 函数的链接。它在一个<li>带有另一个链接的内部。代码在这里:
<li id="aps_pdf1">
   <a target="_blank"" href="....">1testpdf.pdf</a>
      <span style="padding-left:40px">
           <a id="delete-aps_pdf1" class="delete_pdf" title="Delete this PDF." href="#">Delete</a>
      </span>
</li>
delete-aps_pdf1当通过用 jQuery 替换 html 来单击时,我试图用文件上传控件替换第一个链接。这是我到目前为止的代码:
jQuery(document).ready(function($) {
    $('.delete_pdf').each(function(i,e) { //grab the link class delete-pdf
        var id = $(this).attr('id').replace(/delete-/, '');
        var li = $(this).closest('li').attr('id');
        $(this).click(function(){
            //alert('Clicked! '+ id);//$(this).attr('id'));  //THIS WORKS WHEN CLICKED
            //alert(li);
            $(li).replaceWith('<input type="file" style="width: 700px;" name="' + id + '" id="' + id + '" />');
        });
    });
我的 replaceWith 似乎根本不起作用。我对 jquery 比较陌生,我已经完成了这个阅读文档,所以我确定我在某处遗漏了一些东西。
朝着正确方向迈出的一步将不胜感激!