jQuery 使用 ID 创建新的 div?

标签 jquery asp.net ajax html

我的 ASP.NET masterPage.master 中有表单,如果我单击提交,它会通过 ajax 从 masterPage.master.cs 文件中调用一些方法(我在更新面板中有它)。但我想用 jQuery 改进它。所以我有这个:

$('#submit').click(function () {
            $.ajax({
                type: "POST",
                url: '<% Response.Write("~"+Request.Path); %>',
                beforeSend: function () {
                    $(document.createElement('div')).width($('#formBox').width())
                    .height($('#formBox').height())
                    .css({ backgroundImage: 'url(/Static/Img/bc_overlay.png)', position: 'absolute', left: 0, top: 0, margin: "5px", textAlign: "center", color: "#000", display: "none" })
                    .append("<strong>Načítám</strong><br /><img src='Static/Img/ajax-loader.gif' width='33px' height='33px' alt='loading' />")
                    .fadeIn("slow")
                    .prependTo($('#formBox'));
                    $('#formBox').css('position', 'relative');
                },
                success: function () {
                }
            });
        });

因此,如果我点击提交,就会创建新的 div(加载文本和图像,以及很酷的不透明叠加层),但是我如何给这个 div 一些 ID?因为我需要使用它在

success: function () {
                    }

我需要清除此框并在此处写一些文本(错误或成功)。

最佳答案

在创建时设置属性即可

$(document.createElement('div')).attr('id', 'theID')//rest of code

关于jQuery 使用 ID 创建新的 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5314537/

相关文章:

javascript - 如何避免 jquery ui 工具提示出现在子 div 中?

html - 当我调整窗口菜单大小时不保持固定

asp.net - 在 JavaScript 中显示 Modalpopup

c# - Asp.net Webpages 有没有类似于 Razor 中的 Html.Partial 的东西

php - 单击按钮填充列表框

javascript - 如果ajax回调中验证失败,如何停止提交表单

javascript - 清空整个邻居 div 部分

javascript - 检索内联 CSS 样式值

javascript - 使用jquery滚动底部div

jquery - 如何在 Ajax 请求成功后在我看来增加投票总数