gpt4 book ai didi

javascript - 为什么 'label' 标记在 ie8 中不起作用

转载 作者:行者123 更新时间:2023-11-30 17:25:08 26 4
gpt4 key购买 nike

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<input type="checkbox" name="check" style="display:none;" value="check1" id="ch1">
<label for="ch1">check1</label>
<input type="checkbox" name="check" style="display:none;" value="check2" id="ch2">
<label for="ch2">check2</label>
</body>
</html>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
function showValues() {
alert(this.value);
}
$( "input[type='checkbox']" ).on( "click", showValues );
</script>

在 ie10 中点击“check1”文本时如下图所示

enter image description here

但它在 ie8 中不工作

最佳答案

移动<script> <body> 内的标签.

我认为您也想在标签而不是复选框上注册您的点击(因为您实际上并没有显示复选框)。试试这个:

function showValues() {
alert($("#"+$(this).attr("for")).val());
}
$("label").on("click", showValues);

关于javascript - 为什么 'label' 标记在 ie8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24421997/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com