MouseEvent单击获取RangeError:超出最大调用堆栈大小

时间:2019-07-10 09:02:18

标签: javascript dom-events

我试图调度DOM中的tag元素上的事件单击,并且得到:

  

RangeError:超出了最大调用堆栈大小

我该如何解决?

我尝试使用event.stopPropagation(),但无法使用:

var shareButton = document.querySelectorAll('.shrer');

for (var i = 0; i < shareButton.length; i++) {
    shareButton[i].addEventListener('click', function(event) {
        event.preventDefault();
        event.stopPropagation();
        var thisClass = this.className;
        sharer(thisClass)
    })
}

function sharer(shareWith) {
    var jobLink = window.location;
    var subject = document.querySelectorAll('.titleWrap h2')[0].innerHTML;
    var textBody = 'a job for you text';

    if (shareWith.match(/MailShare/)) {
        document.getElementsByClassName(shareWith)[0].href= 'mailto:?subject=' +subject+ '&body=' +textBody+  '%0D%0A' +jobLink+ '';
        document.getElementsByClassName(shareWith)[0].dispatchEvent(new MouseEvent('click', {bubbles: false, cancelable: true, view: window}));
    } 

}

1 个答案:

答案 0 :(得分:0)

使用document.location.href修复

//you only need:
$cotisation = Cotisation::create($request->all());

//you do not need to fill

if ($request->cheque) {
   $cheque     = Cheque::create($request->cheque);
   $cotisation->cheque()->associate($cheque);
   //place save inside of if statement since you only need to save if doing this
   $cotisation->save();
}