【问题标题】:remove appended html删除附加的 html
【发布时间】:2011-04-03 04:12:35
【问题描述】:
   $(function() {
           if(map_flag == 0)
              $("#buttons").append('&nbsp;&nbsp;<input type="button" value="Import" class="ui-state-default ui-corner-all" onclick="javascript:import_q();" />');

       });

function upload_1()
{
  $("#buttons").val('');
   $("#buttons").html('')
}

在upload_1 函数中如何删除附加在$("#buttons") 中的html 我试过 $("#buttons").val(''); $("#buttons").html('');

没用

【问题讨论】:

  • 您的.html('') 版本应该可以工作。你确定upload_1() 会被调用吗?您是否尝试在该函数中放置一个简单的.alert()

标签: javascript jquery jquery-plugins jquery-selectors


【解决方案1】:
$('#buttons').html('');

将替换 #buttons 元素中的 innerHTML

$('#buttons').replaceWith('');

将替换元素 #buttons 本身并将其替换为 ''(无)

旁注:您的代码中有错字,.html() 后面缺少;

【讨论】:

    【解决方案2】:
    <script type="text/javascript">
       $(function() {
                  $("#buttons").append('&nbsp;&nbsp;<input type="button" value="Import" class="ui-state-default ui-corner-all" onclick="javascript:import_q();" />');
    
           });
    
    function upload_1()
    {
       $("#buttons").html('')
    }
    </script>
    <div id="buttons"></div>
    <a href="#"  onclick="javascript:upload_1();" >Clear</a>
    

    对我来说很好用...你是如何初始化 upload_1 函数的?

    【讨论】:

    猜你喜欢
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    相关资源
    最近更新 更多