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),谢谢,这个刚看,不大懂但急着要用
[解决办法]
<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>