【问题标题】:Twitter Bootstrap alert (notification) dynamically change textTwitter Bootstrap 警报(通知)动态更改文本
【发布时间】:2013-08-07 13:24:51
【问题描述】:

简单的问题,但我没有成功找到关于 SO 的满意答案。

当我收到引导警报时:

<div id='alert' class='alert alert-error hide'>Alert.</div>

我希望使用 jQuery 或 Javascript 来控制文本,我刚刚看了this problem 的这个解决方案,但它必须这么复杂吗?真的吗?

【问题讨论】:

标签: javascript jquery twitter-bootstrap


【解决方案1】:

就这么简单:$("#alert").text("My new Text");

【讨论】:

    【解决方案2】:

    参考了解决方案,现在想出了这个:

    HTML:

    <div id='alert' class='hide'></div>
    

    Javascript:

    function showAlert(message) {
          $('#alert').html("<div class='alert alert-error'>"+message+"</div>");
          $('#alert').show();
        }
    showAlert('variable');
    

    工作jsfiddle

    【讨论】:

      【解决方案3】:
      <input type = "button" id = "clickme" value="Click me!"/>
      <div id = "alert_placeholder"></div>
      <script>
      bootstrap_alert = function() {}
      bootstrap_alert.warning = function(message) {
                  $('#alert_placeholder').html('<div class="alert"><a class="close" data-dismiss="alert">×</a><span>'+message+'</span></div>')
              }
      
      $('#clickme').on('click', function() {
                  bootstrap_alert.warning('Your text goes here');
      });
      </script>​
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-29
        • 2014-11-07
        • 1970-01-01
        • 2012-09-04
        • 1970-01-01
        • 1970-01-01
        • 2011-11-30
        • 2012-08-25
        相关资源
        最近更新 更多