javascript - 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'");
}
});
解决方案
我尝试创建一个小示例,用于使用 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 在您的机器上运行我的示例,以检查它是否正常工作。
推荐阅读
- c# - C# 应用程序结束时分配的内存不会被释放
- node.js - 我无法在反应中重定向到另一个页面
- flutter - Flutter SaveArea 启用底部栏不起作用?
- javascript - Javascript平均总和
- spring - MongodbReactive 当你有空结果时该怎么办
- c - 任何想法 ?警告分配使指针从整数而不进行强制转换
- css - 为控件的轨迹栏添加颜色 - 基于 react-bootstrap 的滑块
- mysql - Angular 9 + Springboot REST API 社交登录 OAUTH2
- cplex - 为什么在使用 CPLEX 运行 Minizinc 模型时会创建许多 cpx 文件?
- java - javax.persistence.TransactionRequiredException:Spring 5 中没有正在进行的事务