怎么得到光标所在的ID

如何得到光标所在的ID
本帖最后由 yhw2018 于 2014-03-10 15:05:56 编辑
就是页面上有3个input 进入页面 光标默认在证件号码这个input中闪  我鼠标选中前两 其中一个input时  我在第三个input中的JS方法中能 如何得到 我选中input的 id 


				<div id="center_input_center" align="center">
证件号码:
<input id="sfz" name="sfz" 
style="border: 3px solid #7f9db9;" maxlength="18" />
</div>

<div id="center_input_center" align="center">
查询密码:
<input id="cxmm"  type = "password" name ="cxmm" 
style="border: 3px solid #7f9db9;" maxlength="6" />
</div>
<div id="center_input_center" align="center">
例:
<input id="t"   name ="t" onclick="modi()"
style="border: 3px solid #7f9db9;"  />
</div>


------解决方案--------------------
不是很清楚你要实现的 我知道的有两种
1.定义一个全局变量 选中哪个就把选中的id赋值给这个全局变量
2.在input前加一个隐藏的checkbox点击哪个就把前面的状态选上另一个清空
------解决方案--------------------
<!DOCTYPE HTML>
<html lang="en">
<head>
  <title>Mighty Gumball (Json)</title>
  <meta charset="utf-8">

</head>

<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-beta1.js"></script>

  <script type = "text/javascript">
   function modi(){
    var ckObj = $(":checkbox:checked");
    console.log(ckObj.prev().prop('id'))
   }
  </script>
          <div id="center_input_center" align="center">
          
          证件号码:
          <input id="sfz" name="sfz" 
            style="border: 3px solid #7f9db9;" maxlength="18" />
            <input type="checkbox" name="ck" checked="checked">
        </div>
        
        <div id="center_input_center" align="center">
        
          查询密码:
          <input id="cxmm"  type = "password" name ="cxmm" 
            style="border: 3px solid #7f9db9;" maxlength="6" />
            <input type="checkbox" name="ck">
        </div>
        <div id="center_input_center" align="center">
          例:
          <input id="t"   name ="t" onclick="modi()"
            style="border: 3px solid #7f9db9;"  />
        </div>


</body>
</html>