日期:2014-05-17  浏览次数:21048 次

如何取得当前点击的div的值
<script   language= "JavaScript ">
function   clickme()
{
if   (document.getElementById( " ").value   !=   " ")
{
  alert();
}
}
</script>

<form   name= "form1 "   method= "post ">
    <div   onclick= "clickme(); "   id= "one "> <a   href= "# "> 点我 </a> </div>
    <div   onclick= "clickme(); "   id= "two "> <a   href= "# "> 点我 </a> </div>
    <div   onclick= "clickme(); "   id= "three "> <a   href= "# "> 点我 </a> </div>
</form>

假如我有100个div,点击某个div就把它的id   alert出来!

------解决方案--------------------
没测试......自己测试吧.

<script type= "text/javascript " src= "http://code.jquery.com/jquery-latest.pack.js "> </script>
<script language= "JavaScript ">
$(document).ready(function(){
$( "div ").click(function(){
$.post( 'receive.asp ',{ 'qq ':$(this).attr( 'id '), 'id ':$(this).attr( 'id ')}, function(xml){alert(xml);});
});
});
</script>

<form name= "form1 " method= "post ">
<input type= "text " name= "qq " value= " "/>
<div id= "one "> <a href= "gg1.htm " target= "_blank "> 我是广告 </a> </div>
<div id= "two "> <a href= "gg2.htm " target= "_blank "> 我是广告 </a> </div>
</form>
------解决方案--------------------
<!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 ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<style type= "text/css ">
<!--
#tt {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 181px;
top: 165px;
border:1px #ff0000 solid;
}
-->
</style>
<script language= "javascript ">
function getId(str)
{
var id=document.getElementById(str).id;
alert(id);
}
</script>
</head>

<body>
<div id= "tt " onclick= "getId(this.id) "> 测试下 </div>
</body>
</html>

div的ID取得了,写入数据库就看着用AJAX传吧