效果如上图:
用javascript实现:当点击小明或小张的复选框时,显示出相应的性别。窗口紧跟随在姓名旁边。每个性别窗口都应是独立的哦。
用javascript实现:当点击小明或小张的复选框时,显示出相应的性别。窗口紧跟随在姓名旁边。每个性别窗口都应是独立的哦。
解决方案 »
- easyui layout 布局问题
- 求个金钱验证JS
- 怎么调用JSP页面中循环里面的onclick方法-急!
- 用三个文本框。在前两个文本框输入数字,在第三个文本框中显示前两个文本框中的数字的和。
- Javascript版泡泡龙,经典重现!
- file类型的input很奇怪的一个问题,不知大家遇到过没有,请大家进来看看!!
- SWFOject问题,请求参数为什么返回不了值
- 用window.open()方法打开的新窗口,如何将其设置为"模态"窗口,即如果不关闭此窗口,就无法对其他窗口进行操作
- 怎么屏蔽以下按键:Ctrl+N, F5, 我找不出来了,30分送
- fso = new ActiveXObject("Scripting.FileSystemObject");???
- 急!急!急!关于html中的onclick 与 jQuery中的onclick
- 求一点思路(类似Google Map效果)
<html>
<head>
<title>floatDiv2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
div {
border: 1px solid black;
background-color: #E5F0FB;
position: absolute;
width: 150px;
height: 100px;
display: none;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function () {
$(document).click(function (e) {
if (e.target.id != "show_box1" && e.target.id != "show_box2") {
$("div[id^='show']").hide();
}
});
$(":checkbox").click(function (e) {
$("div[id^='show']").hide();
$("#show_"+ this.id).css({left: e.clientX, top: e.clientY}).show();
return false;//防止冒泡
});
});
</script>
</head>
<body>
<input type="checkbox" id="box1"/>
<input type="checkbox" id="box2"/>
<div id="show_box1" class="a b c"></div>
<div id="show_box2" class="myCls"></div>
</body>
</html>
可以自己设性别并在前段保存<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh" dir="ltr">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var data = [
{name: "小张", sex: true},
{name: "小李", sex: false},
{name: "小王", sex: true}
];
function init(){
createList(data);
bindEvents();
}
function createList(data){
var html = new StringBuffer();
$.each(data, function(key, value){
html.append("<input class='Names' type='checkbox' id='Name_").append(key).append("' /><label for='Name_").append(key).append("'>").append(value.name).append("</label>");
});
$("#DataList").html(html.toString());
}
$(document).ready(init);
//Events
function bindEvents(){
$(".Names").click(doNameClick);
$(".Sex").click(doSexClick);
}
function doNameClick(e){
var elem = $(e.target);
$(".Names").removeAttr('checked');
$(elem).attr('checked', 'true');
showSexBox(elem[0].id);
}
function doSexClick(e){
$(".Sex").removeAttr('checked');
var elem = $(e.target);
$(elem).attr('checked', 'true');
var sex = $(elem)[0].id == "Male" ? true : false;
var index = $("#Sex").attr('n');
data[index].sex = sex;
}
function showSexBox(id){
var l = $("#"+id).offset().left + 20;
var t = $("#"+id).offset().top + 50;
var index = id.split('_')[1];
var sex = data[index].sex;
$(".Sex").removeAttr('checked');
(sex == true) ? $("#Male").attr('checked', 'true') : $("#Female").attr('checked', 'true');
$("#Sex").css({left: l, top: t, display: 'block'});
$("#Sex").attr('n', index);
}
//StringBuffer类 - by Wang
var StringBuffer = function() {
this._strings = new Array();
};
StringBuffer.prototype.append = function(str) {
this._strings[this._strings.length] = str;
return this;
};
StringBuffer.prototype.toString = function(str) {
if (!str) {
return this._strings.join('');
} else {
return this._strings.join(str);
};
};
</script>
<style type="text/css">
#DataList
{}
#Sex
{position:absolute;border:solid 1px #ccc;display:none;}
</style>
</head>
<body>
<div id="DataList"></div>
<div id="Sex">
<input type="checkbox" id="Male" class="Sex" name="SexGroup"/><label for="Male">男</label>
<input type="checkbox" id="Female" class="Sex" name="SexGroup"/><label for="Female">女</label>
</div>
</body>
</html>
还有3L编译通不过是因为你没有在本机放置jquery.js. Lz这个都看不出来?