javascript jQuery AJAX:单击后将 HTML 加载到 DIV 元素中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12581237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:34:36  来源:igfitidea点击:

jQuery AJAX: load HTML into DIV element after click

javascriptjqueryhtmlajax

提问by fpellegrino

i would like to load (or be visible) an HTML/ASP.NET email form after the user clicked in a link/button. I have used this code but it doesn't work:

我想在用户单击链接/按钮后加载(或可见)一个 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>

where #imgMail is the ID of the link/button and the #mailForm is the ID of the DIV element into load the content.

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

How can i resolve this problem? P.S. The elements are not into a form tag.

我该如何解决这个问题?PS 元素没有变成表单标签。

Thanks.

谢谢。

回答by StaticVariable

Use this..

用这个..

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