首页 > 解决方案 > Javascript Prop 函数在 IE 11 中不起作用

问题描述

我正在尝试选中一个复选框,但它在 IE11 中不起作用。它在 Chrome 中运行良好。有人可以向我解释为什么这段代码在这些浏览器上不起作用吗?

// 01_certify_01
$(function() {
  $("#calCarStartBtn").click(function() {
    window.location.href = './src/views/01_certify_01.php?mode=calc';
  });

  $("#histCalCarBtn").click(function() {
    window.location.href = './src/views/01_certify_01.php?mode=hist';
  });

  var textObj = $(".textarea");
  var warningObj = $(".warning-box");
  textObj.hide();
  warningObj.hide();

  $("#checkboxAgreeAll").click(function() {
    var chk = $(this).prop("checked");
    if (chk) {
      $("input[type='checkbox']").prop("checked", true);
      $("#certify01 label").css("background-image", "url('./../img/check_on.png'");
      warningObj.hide();
    } else {
      $("input[type='checkbox']").prop("checked", false);
      $("#certify01 label").css("background-image", "url('./../img/check_off.png'");
    }
  });

  $("#checkbox1").click(function() {
    checked = $(this).prop("checked");
    var l = $("label[for='checkbox1']");
    l.css("background-image", "url('./../img/check_on.png'");
    warningObj.hide();

    if (!checked) {
      $("#checkboxAgreeAll").prop("checked", checked);
      $("label[for='checkboxAgreeAll']").css("background-image", "url('./../img/check_off.png'");
      l.css("background-image", "url('./../img/check_off.png'");
    }
  });

标签: javascriptjqueryinternet-explorer-11

解决方案


我尝试创建一个小示例,用于使用 IE 11 浏览器测试 prop 功能。

根据我的测试结果,道具功能正在检查复选框。

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>
<body>
<input type="checkbox" id="vehicle1" value="Bike"> I have a bike<br>
  <input type="checkbox" id="vehicle2" value="Car"> I have a car<br>
 
  <input type="button" value="check" id="btn"> <input type="button" value="uncheck" id="btn1">
  <script>
$(document).ready(function(){

  $("#btn").click(function(){
 
    $( "#vehicle1" ).prop( "checked", true );
 
    $( "#vehicle2" ).prop( "checked", true );
	
  });
  
   $("#btn1").click(function(){
 
    $( "#vehicle1" ).prop( "checked", false );
 
    $( "#vehicle2" ).prop( "checked", false );
	
  });
});
</script>
</body>
</html>

IE 11 中的输出:

在此处输入图像描述

其他一些代码行可能会导致此问题。尝试检查控制台以查看是否有任何错误消息。它可以给出关于这个问题的想法。

尝试清除缓存并再次尝试测试问题。

我建议您使用 IE 11 在您的机器上运行我的示例,以检查它是否正常工作。


推荐阅读