3

Simple question, but I didn't succeed finding a satisfactory answer on SO.

When I have a bootstrap alert:

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

I want the text to be controlled using either Javascript of by jQuery, I just looked at this solution to this problem, but does it have to be so complicated? Really?

4

3 回答 3

7

很简单:$("#alert").text("My new Text");

于 2017-03-31T14:52:52.550 回答
6

引用了解决方案,现在想出了这个:

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

于 2013-08-07T13:58:27.180 回答
0
<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>​
于 2015-06-01T12:20:26.540 回答