javascript - jQuery AJAX : load HTML into DIV element after click

标签 javascript jquery html ajax

我想在用户单击链接/按钮后加载(或可见)HTML/ASP.NET 电子邮件表单。我已经使用了这段代码,但它不起作用:

<script type="text/javascript">
    $(document).ready(function () {
        $("#imgMail").click(function (htm) {
            $.get("mailform.html"),
                $("#mailForm").append(htm)); //i have tryed also with .html() function.
        });
    });
</script>

#imgMail 是链接/按钮的 ID,#mailForm 是加载内容的 DIV 元素的 ID。

我该如何解决这个问题? 附言元素不在表单标签中。

谢谢。

最佳答案

用这个..

<script type="text/javascript">
    $(document).ready(function () {
        $("#imgMail").click(function() {
            $.get("mailform.html",function(data){
                $("#mailForm").append(data);
            });
        });
    });
</script>

关于javascript - jQuery AJAX : load HTML into DIV element after click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12581237/

相关文章:

jquery - 在 jquery 自动完成中获取值

html - 为什么我的内容区域停在页脚之前?

html - 多语言网站和 rtl 方向 - 最佳实践

javascript - 检查对象数组中的所有属性值是否相同

javascript - 如何从 ul li 项目中获取文本?

javascript - 传递并附加 JavaScript 窗口方法?

javascript - 如何使用 Javascript 在 Html 页面上添加计时器

javascript - 如何从jquery中的<ul>中的指定<li>获取最接近左侧或右侧的<li> id

javascript - 即使刷新页面后如何存储禁用按钮的状态?

javascript - after() 与 fadein() jquery 不工作