无法在jquery中获取表单标记?

时间:2017-10-03 11:56:28

标签: javascript jquery

我的表格如下所示

  <form class="card-photo-body single-image lot-photo dropzone clickable dz-clickable dz-started" id="dropzone-11" action="/Lot/SaveUploadFile" method="post" data-image-type="11" data-image="7bdae02e-d98e-473a-b23d-f54502f99387">
                                    <input type="hidden" name="listingid" value="98b1a9ef-2888-40b4-8622-cef2a88a2da4">
                                    <input type="hidden" name="type" value="11">
                                    <input type="file" style="display: none;" accept="image/*">
                                    <div class="dz-message" data-dz-message="" style="display: none;">
                                        <svg width="78" height="66">
                                            <title>Image Upload</title>
                                            <desc>Camera</desc>
                                            <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/content/images/sprite.svg#camera"></use>
                                        </svg>
                                            <div class="card-photo-body-text">
                                                Drag photo here or <strong>upload</strong>
                                            </div>
                                    </div>
                                <div class="preview dz-success dz-complete" data-image="7bdae02e-d98e-473a-b23d-f54502f99387">
                            <div class="dz-image">
                                <img src="" data-dz-thumbnail="">
                                <div class="image" style="">
                                    <img src="/Lot/Image?id=7bdae02e-d98e-473a-b23d-f54502f99387">
                                </div>
                            </div>
                            <div class="progress" style="display: none;">
                                <div class="bar" style="width: 0%;" data-dz-uploadprogress=""></div>
                            </div>
                                <img remove-file="" class="remove" src="/Content/images/close.png">
                        </div></form>

我正在尝试使用事件

获取函数中的表单元素
  $(event.target).closest('form')

但我期待上面的html,但我只得到了形式elemnt的内部部分

   <input type="hidden" name="listingid" value="98b1a9ef-2888-40b4-8622-cef2a88a2da4">
                                    <input type="hidden" name="type" value="11">
                                    <input type="file" style="display: none;" accept="image/*">
                                    <div class="dz-message" data-dz-message="" style="display: none;">
                                        <svg width="78" height="66">
                                            <title>Image Upload</title>
                                            <desc>Camera</desc>
                                            <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/content/images/sprite.svg#camera"></use>
                                        </svg>
                                            <div class="card-photo-body-text">
                                                Drag photo here or <strong>upload</strong>
                                            </div>
                                    </div>
                                <div class="preview dz-success dz-complete" data-image="7bdae02e-d98e-473a-b23d-f54502f99387">
                            <div class="dz-image">
                                <img src="" data-dz-thumbnail="">
                                <div class="image" style="">
                                    <img src="/Lot/Image?id=7bdae02e-d98e-473a-b23d-f54502f99387">
                                </div>
                            </div>
                            <div class="progress" style="display: none;">
                                <div class="bar" style="width: 0%;" data-dz-uploadprogress=""></div>
                            </div>
                                <img remove-file="" class="remove" src="/Content/images/close.png">
                        </div>

我该怎么做才能获得整个表格标签?

1 个答案:

答案 0 :(得分:1)

你想得到整个HTML吗?使用$(event.target).closest('form')[0] 如果只使用$(event.target).closest('form').html(),您将获得innerhtml