簡體   English   中英

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

[英]Javascript Prop function not work in 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'");
    }
  });

我已經檢查了@TJ Crowder 的答案( 這里)及其在 IE 11 中的工作

試試這個來檢查和取消選中一個復選框。

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

我嘗試創建一個小樣本來使用 IE 11 瀏覽器測試道具 function。

根據我的測試結果,道具 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>

IE 11 中的 Output:

在此處輸入圖像描述

其他一些代碼行可能會導致此問題。 嘗試檢查控制台以查看是否有任何錯誤消息。 它可以給出關於這個問題的想法。

嘗試清除緩存並再次嘗試測試問題。

我建議您使用 IE 11 在您的機器上運行我的示例,以檢查它是否正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM