日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Uncaught RangeError: Maximum call stack size exceeded問題解決

作者:青衫· 更新時間: 2022-02-26 編程語言

Uncaught RangeError: Maximum call stack size exceeded問題解決

html:

        <div id="item_fx"  size="0,180,100%,15,BP1">
            <div id="fx_wtxx">
                <input id="fx_check"  type="checkbox" ></input>
                <label id="fx_name1"  for="fx_check" text="腹瀉"></label>
                <label id="fx_name3"  text="次/天"  ></label>
                <input id="fx_input" disabled  placeholder=""  maxlength="100"  border-radius="5"></input>
            </div>
            
        </div>

js:

$('#fx_wtxx').click(function() {
        var fx_check = document.getElementById('fx_check');
        if(fx_check.checked){
            $('#fx_input').removeAttr("disabled");
            $('#fx_input').focus();
            $('#fx_input').click();
        }else {
            $('#fx_input').attr("disabled",'true');
            $('#fx_input').blur();
        }
    });

點擊#fx_wtxx時,觸發#fx_input,結果代碼報錯:Maximum call stack size exceeded。

報錯原因:出現無限循環。
代碼實現的是點擊div時觸發input的點擊事件,但是這個input是被包裹在div內部的,所以input的點擊事件觸發后,通過事件冒泡又觸發了div的點擊事件,div的點擊事件又去觸發input的點擊事件,input的點擊事件再次冒泡觸發div的點擊事件……如此一來便造成了無限循環,所以報錯:Maximum call stack size exceeded。

解決方法:將input移出div即可。

原文鏈接:https://blog.csdn.net/lyc___/article/details/121417622

欄目分類
最近更新