Twitter bootstrap 通过不放置任何div';这页上有什么

Twitter bootstrap 通过不放置任何div';这页上有什么,twitter-bootstrap,Twitter Bootstrap,我可以在引导中写入动态警报吗 下面是我尝试的示例代码 <head> <script src="jquery-1.9.1.js"></script> <script src="bootstrap-current/bootstrap.js"></script> <script> $("<div/>").addClass("alert alert-error").html("te

我可以在引导中写入动态警报吗

下面是我尝试的示例代码

<head>
    <script src="jquery-1.9.1.js"></script>
    <script src="bootstrap-current/bootstrap.js"></script>
    <script>
        $("<div/>").addClass("alert alert-error").html("test").alert();
    </script>
</head>

$(“”).addClass(“警报错误”).html(“测试”).alert();

是,您可以动态创建警报。不过,您需要更改代码中的一些内容

$("<div/>").addClass("alert alert-danger").html("test").appendTo("yourSelector");
$(“”).addClass(“警报危险”).html(“测试”).appendTo(“您的选择器”);
退房

这是非常基本的jQuery。你可能想在网上找到一些教程来学习

试试这个:

您可以在此处使用三种不同的
样式类
,如
警报成功
警报危险
警报警报警告

 $(document).ready(function () {
            ShowMessagesUsingPopup("alert", "alert alert-success");
        });



        function ShowMessagesUsingPopup(message, styleName) {

            var div = document.createElement("div");
            div.id = "DivMessage";
            div.style.bottom = "10px";
            div.style.right = "25px";
            div.style.width = "400px";
            div.style.position = "fixed";
            div.style.zIndex = "1060";

            var spanTag = document.createElement('span');
            if (styleName == "alert alert-success") {
                spanTag.className = "glyphicon glyphicon-ok";
            }
            else if (styleName == "alert alert-danger") {
                spanTag.className = "glyphicon glyphicon-ban-circle";
            }
            else if (styleName == "alert alert-warning") {
                spanTag.className = "glyphicon glyphicon-warning-sign";
            }
            div.appendChild(spanTag);

            var buttonTag = document.createElement('button');
            buttonTag.type = "button";
            buttonTag.className = "close";
            buttonTag.textContent = "x";
            buttonTag.setAttribute("data-dismiss", "alert");
            div.appendChild(buttonTag);

            var strongTag = document.createElement('strong');
            strongTag.textContent = " " + message;
            div.appendChild(strongTag);

            div.style.display = "block";
            div.className = styleName + " alert-dismissable";
            $(".alert").alert();
            document.body.appendChild(div);

        }

你已经自己试过了吗?这是要求的一部分,我试过上面的代码。他说:“我不想在页面中为modals/alerts添加很多引导模板(div)。你已经尝试过span元素了吗?”。你有一个div.@jordan啊,我在标题中漏掉了。