【问题标题】:jquery works in Firefox, Edge, but not Chromejquery 适用于 Firefox、Edge,但不适用于 Chrome
【发布时间】:2019-11-15 14:14:31
【问题描述】:

我有以下代码在 Firefox、Edge 中有效,但在 Chrome 中无效。

            <script>
            function hst_collected() {
            var value = $( 'input[name=interpret_hst_collected]:checked' ).val();
            if (value == 1) {
               $('#recording2').hide();
               $('#recording3').hide();
            }
            if (value ==2) {
               $('#recording2').show();
               $('#recording3').hide();
            }
            if (value ==3) {
              $('#recording2').show();
              $('#recording3').show();
            }
            }
            $( document ).ready(function() {
                hst_collected();
            });

            $('input[name=interpret_hst_collected]').change(function(){
                hst_collected();
            });
            </script>

非常感谢任何想法和建议。

【问题讨论】:

  • 你能给我们提供一个最低限度的工作示例吗?
  • 究竟是什么不工作? hst_collected(); 准备好文件了吗?或 hst_collected(); 更改事件?或者两者都不起作用?
  • 您需要指定问题的上下文;您的页面上有哪些元素?预期的行为是什么,实际结果是什么?

标签: javascript jquery google-chrome firefox microsoft-edge


【解决方案1】:

谢谢。

我在这篇文章中找到了解决方案:Chromium's XSS auditor refused to execute a script

我需要绕过 Chrome 的 XSS 保护。它现在正在工作。

谢谢。

【讨论】:

    【解决方案2】:

    请参考以下代码并修改您的代码(假设您使用单选按钮):

    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
    <script>
        function hst_collected() {
            var value = $('input[name="interpret_hst_collected"]:checked').val();
            if (value == 1) {
                $('#recording2').hide();
                $('#recording3').hide();
            }
            if (value == 2) {
                $('#recording2').show();
                $('#recording3').hide();
            }
            if (value == 3) {
                $('#recording2').show();
                $('#recording3').show();
            }
        }
        $(document).ready(function () {
            hst_collected();
            $('input[name="interpret_hst_collected"]').change(function () {
                hst_collected();
            });
        });
    </script>
    <div>
        <input type="radio" name="interpret_hst_collected" value="1" />Level I
        <input type="radio" name="interpret_hst_collected" value="2"/>Level II
        <input type="radio" name="interpret_hst_collected" value="3"/>Level III
    
        <div id="recording2" style="width:50px; height:50px; background-color:antiquewhite">
            a
        </div>
        <div id="recording3" style="width:50px; height:50px; background-color:aqua">
            b
        </div>
    </div>
    

    这样的结果(使用 Chrome 版本 75.0.3770.100 和 Microsoft Edge 44.18362.1.0):

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 2023-01-14
      • 2011-05-24
      • 1970-01-01
      相关资源
      最近更新 更多