简体   繁体   English

在html的同一页面中打开子链接

[英]open sub link in the same page in html

in html i am having the following tags. 在html中,我具有以下标记。

  <a href="javascript:void(0)"><span id=M26>2011-2012</span></a>
  <div id=c26 STYLE="display:none">

  <a href="javascript:void(0)"><span id=M27>2012-2013</span></a>
  <div id=c26 STYLE="display:none">   

on Clicking on 2011-2012 or on 2012-2013 i want to set displaye property of div tag . 在单击2011-2012或2012-2013时,我要设置div标签的displaye属性。 I am using the following java script code for this and i am calling the javascript function in body tag. 我为此使用以下Java脚本代码,并且在body标签中调用了javascript函数。 the output is showing style and display is not an object or property. 输出显示样式,显示不是对象或属性。

     <script language="javascript">
   function clickHnadler()
   {
   var xid= document.getElementsByTagName("span");
   var xsp= xid[0].id;   
  alert("Span id is "+xsp);
  if(xsp.charAt(0)=="M")
  {
   var oC = document.all("C"& xsp.substring(1,2));
   if(oC.STYLE.display == "none")
   {
    oC.Style.Display = "";
   }
   else{
     oC.Style.Display = "none";
     }
    } 
  }
 </script>  

use jquery: 使用jQuery:

you can pass in the function the element or the Id: ex: 您可以将元素或ID传递给函数:例如:

<a href="#" onclick="clickhandler(this)"><span id=M26>2011-2012</span></a>

function clickHnadler(element)
{
  var id = $(element > span).attr(id);
  id[0] = 'c'; //not the nicest way, maybe use a replace or something like that
  $(id).show(); //or $(id).css('display','list');
}

You may use clickHandler has following way, function clickHandler(e) { window.document.links[0].handleEvent(e); 您可以使用clickHandler具有以下方式,即功能clickHandler(e){window.document.links [0] .handleEvent(e); } }

You need to bind event spacifically to elements you want to handle click for. 您需要将事件特定地绑定到要处理click的元素。 for more information please refer following link, 有关更多信息,请参考以下链接,

http://docs.oracle.com/cd/E19957-01/816-6409-10/evnt.htm#1009606 http://docs.oracle.com/cd/E19957-01/816-6409-10/evnt.htm#1009606

Based on what i understand from your question, I come up with this. 根据我对您的问题的理解,我提出了这个建议。

    <script type="text/javascript" src="jquery1.8.js"></script>
    <a href="javascript:void(0)" onclick="$(this).next('div').toggle()"><span id=M26>2011-2012</span></a>
    <div id=c26 STYLE="display:none">
    2011-2012 details</div>
    <br />
    <a href="javascript:void(0)" onclick="$(this).next('div').toggle()"><span id=M27>2012-2013</span></a>
    <div id=c26 STYLE="display:none">   
        2012-2013 details
    </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM