gpt4 book ai didi

jquery ui 单选按钮验证在 Firefox 中有效,但在 IE 中出错。 。

转载 作者:行者123 更新时间:2023-12-01 03:42:13 24 4
gpt4 key购买 nike

我有一个页面,使用一些 jquery ui 来设置一些单选按钮的样式。当用户选择一个时,jquery 会识别出选择了哪一个,然后更改下面相应 div 的背景颜色(最终,它们实际上会调用 .load 将动态页面上的内容填充到 div 中)网站,但目前,只需为 div 着色就可以了)。

它在 Firefox 中工作得很好,但在 Internet Explorer(或有些人称之为 Internet Exploder)中,它提示“radio1”未定义。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Button - Checkboxes</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>

$(document).ready(function() {
$(function() {
$( "#radio" ).button();
$( "#format" ).buttonset();
});

$('input:radio').change(function(){
if($(radio1).is(':checked')){
$("#first").css("background-color","yellow");
$("#second").css("background-color","white");
$("#third").css("background-color","white");
}else if($(radio2).is(':checked')){
$("#first").css("background-color","white");
$("#second").css("background-color","red");
$("#third").css("background-color","white");
}else if($(radio3).is(':checked')){
$("#first").css("background-color","white");
$("#second").css("background-color","white");
$("#third").css("background-color","blue");
} else {
$("#first").css("background-color","white");
$("#second").css("background-color","white");
$("#third").css("background-color","white");
}
});
});

</script>
<style>
#format { margin-top: 2em; }
</style>
</head>
<body>


<form>
<div id="format">
<input type="radio" id="radio1" name="radio" checked="checked" /><label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" /><label for="radio2">Choice 2</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
</div>
</form>

<!-- The following divs will end up being populated via an ajax call based on checkbox selections -->
<!-- Ultimately, checking a given checkbox should toggle the corresponding div -->
<div id="first">
First Div
</div>
<div id="second">
Second Div
</div>
<div id="third">
Third Div
</div>

</body>
</html>

最佳答案

选择器应使用 id 选择器来访问单选按钮。我不知道这在 FF 中是如何工作的。

        $('input:radio').change(function(){
if($("#radio1").is(':checked')){
$("#first").css("background-color","yellow");
$("#second").css("background-color","white");
$("#third").css("background-color","white");
}else if($("#radio2").is(':checked')){
$("#first").css("background-color","white");
$("#second").css("background-color","red");
$("#third").css("background-color","white");
}else if($("#radio3").is(':checked')){
$("#first").css("background-color","white");
$("#second").css("background-color","white");
$("#third").css("background-color","blue");
} else {
$("#first").css("background-color","white");
$("#second").css("background-color","white");
$("#third").css("background-color","white");
}
});

关于jquery ui 单选按钮验证在 Firefox 中有效,但在 IE 中出错。 。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18198466/

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