专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 其他开发语言

ajax,怎么用超链接触发

发布时间:2011-06-30 07:27:02 文章来源:www.iduyao.cn 采编人员:星星草
ajax求助,如何用超链接触发
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;

if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  }
  }
var queryString = location.href.substring(location.href+1);
var parameters = queryString.split("/"); 
var id=parameters[parameters.length-1].split(".");
alert(id[0]);
var str=id[0];
xmlhttp.open("GET","/ajax/click.php?q="+str,true);
xmlhttp.send();
}

</script>
</head>
<body>
<form action="">
<a href="#" onclick="showHint(this.value)" value="1" >超链接</a>
</form>
</body>


<a>中如何写才能触发function showHint(str),谢谢,这个刚看,不大懂但急着要用

------解决方案--------------------
HTML code
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;

if (str.length==0)
   {  
  document.getElementById("txtHint").innerHTML="";
   return;
   }
if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
   {
   document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
   }
   }
var queryString = location.href.substring(location.href+1);
var parameters = queryString.split("/");  
var id=parameters[parameters.length-1].split(".");
alert(id[0]);
var str=id[0];
xmlhttp.open("GET","/ajax/click.php?q="+str,true);
xmlhttp.send();
}

</script>
</head>
<body>
<form action="">
<a id="myhref" href="#" onclick="showHint(document.getElementById('myhref').attributes['value'].value+'')" value="1" >超链接</a>
</form>
</body>
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: