【问题标题】:jquery - Clear modal content without hiding the boxjquery - 清除模态内容而不隐藏框
【发布时间】:2016-05-22 10:16:45
【问题描述】:

q我正在尝试清除模态正文中的内容,而不实际关闭模态框。理论上,新的报价按钮会改变报价。正如我现在拥有的那样,它所做的就是继续在下面添加报价。

通过我的搜索,我看到这个回答说关闭盒子并使用 .removeData() 或等等。

下面是模态框的代码。

<div class="modal in" id="journalModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="myModalLabel">Quotes for Life</h4>
      </div>
      <div class="modal-body" id="text">
      </div>
      <div class="modal-footer">
        <button onclick="quoteClick()" type="button" class="btn btn-default btn2">New Quote</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>

这是我用来拉取 api 的脚本

function apiGrab(){
 $.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&    filter[posts_per_page]=1&callback= function(a) {
  $(".modal-body").append(a[0].content + "<p>— " + a[0].title + "</p>")
 });
}

【问题讨论】:

    标签: javascript jquery modal-dialog


    【解决方案1】:

    在你的quoteclick函数中这样使用

    function quoteClick()
    { 
     document.getElementById("text").innerHTML = "";
    }
    

    这将从对话框中清除旧内容并继续进行进一步处理

    【讨论】:

    • 这行不通。模态框不被视为文本区域,这是可以工作的。我只是决定将其更改为在文本框而不是模态框中工作,因为您似乎无法刷新模态框上的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    相关资源
    最近更新 更多