简体   繁体   English

Javascript 道具 function 在 IE 11 中不起作用

[英]Javascript Prop function not work in IE 11

I am trying to check a checkbox but it's not working in IE11.我正在尝试选中一个复选框,但它在 IE11 中不起作用。 It works fine in Chrome.它在 Chrome 中运行良好。 Can someone explain to me why this code doesn't work on these browsers?有人可以向我解释为什么这段代码在这些浏览器上不起作用吗?

// 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'");
    }
  });

I have checked @TJ Crowder answer ( here ) and its works in IE 11我已经检查了@TJ Crowder 的答案( 这里)及其在 IE 11 中的工作

try this for checking and unchecking a checkbox.试试这个来检查和取消选中一个复选框。

if(!($("input")[0].checked == true))
{
  $("input")[0].setAttribute("checked", "checked");
}
else
{
  $("input")[0].removeAttribute("checked", "checked");
}

I try to create a small sample for testing the prop function with IE 11 browser.我尝试创建一个小样本来使用 IE 11 浏览器测试道具 function。

Based on my testing result, prop function is checking the checkbox fine.根据我的测试结果,道具 function 正在检查复选框。

 <: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>

Output in IE 11: IE 11 中的 Output:

在此处输入图像描述

It can be possible that some other line of code cause this issue.其他一些代码行可能会导致此问题。 Try to check the console to see whether there is any error message.尝试检查控制台以查看是否有任何错误消息。 It can give the idea about the issue.它可以给出关于这个问题的想法。

Try to clear the cache and again try to test the issue.尝试清除缓存并再次尝试测试问题。

I suggest you to run my sample on your machine with IE 11 to check whether it is working or not.我建议您使用 IE 11 在您的机器上运行我的示例,以检查它是否正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM