0

我正在尝试这样做,因此当您单击特定的 div 时,它会触发一个输入按钮以打开 uploadcare 小部件。

这是有问题的HTML

<div class="col-md-6 image-preview-single">
<img src="" alt="" class="img-responsive card-shadow hidden">
    <div id="logo-upload" class="add-new-short add-new-home-realtor card-shadow-mini btn-file uploader-homicity" style="display:block;text-decoration:none; cursor: pointer;">
        <i class="fa fa-photo"/>
        <input type="hidden" role="uploadcare-uploader" name="logo" data-upload-url-base="" data-images-only="true" data-crop="150x150" data-clearable="true" id="logo-input">
            <div class="uploadcare-widget uploadcare-widget-option-clearable uploadcare-widget-status-ready" data-status="ready">
                <div class="uploadcare-widget-dragndrop-area">
                    Drop a file here
                </div>
                <div class="uploadcare-widget-status uploadcare-widget-circle uploadcare-widget-circle--canvas">
                    <canvas width="56" height="56"/>
                </div>
                <div class="uploadcare-widget-text">
                </div>
                <div tabindex="0" role="button" class="uploadcare-widget-button uploadcare-widget-button-open">Choose an image</div>
                <div tabindex="0" role="button" class="uploadcare-widget-button uploadcare-widget-button-cancel">Cancel</div>
                <div tabindex="0" role="button" class="uploadcare-widget-button uploadcare-widget-button-remove">Remove</div>
            </div> 
    </div>

和有问题的Jquery

$( '#logo-upload' ).on( 'click', function() {
    $('input#logo-input').click();
});

这是控制台错误

Uncaught RangeError: Maximum call stack size exceeded
    at RegExp.exec (<anonymous>)
    at n.fn.init (jquery.min.js:2)
    at n (jquery.min.js:2)
    at HTMLDivElement.<anonymous> (uploadcare.js:72)
    at HTMLDivElement.dispatch (jquery.min.js:3)
    at HTMLDivElement.r.handle (jquery.min.js:3)
    at Object.trigger (jquery.min.js:4)
    at HTMLInputElement.<anonymous> (jquery.min.js:4)
    at Function.each (jquery.min.js:2)
    at n.fn.init.each (jquery.min.js:2)

我在这方面缺少什么?

谢谢

4

4 回答 4

2

您还需要在输入单击时添加此事件:

$('input#logo-input').on('click', function(e) {
    e.preventDefault();
    e.stopPropagation();
    ...your code
});

您需要停止传播,因为您创建了无限循环。当您触发单击输入时,此输入位于logo-uploaddiv 内,单击输入会传播到此容器,这会创建无限循环。

于 2017-05-31T16:16:01.033 回答
1

两种选择:

  1. 使用 a<label>仅通过 html 激活输入:

    <label for="yourId">Click here<label> <input id="yourId" type="text" />

  2. 使用focus()而不是click()withstopPropagation()stopPropagation()

    $('#logo-upload' ).on( 'click', function(e) { e.preventDefault(); e.stopPropagation(); $('input#logo-input').focus(); });

于 2017-05-31T16:17:53.100 回答
0

就这样做。

var inputSP = input.click(function (e) { e.stopPropagation(); });

dropper.on('click', function (e) {
   e.stopPropagation();   
    // here we first stop propagation then make a call to click event 
   inputSP; 
   input.click();
});
于 2018-02-17T19:29:43.870 回答
0

好的,

所以你想打开 Uploadcare对话框,而不是小部件

首先,从您的页面中删除所有小部件的 HTML 代码,它是由库添加的,应该在服务文档中。二、使用以下代码

$('#logo-upload').on('click', function() {
    uploadcare.Widget(input_selector).openDialog();
});
于 2017-06-01T12:43:27.297 回答