a标签 href onclick调用函数的问题
<!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=utf-8" />
<title></title>
<style type="text/css">
body
{
margin: 0 auto;
padding: 0;
}
a:focus
{
outline: none;
}
#pn
{
background: #e8e8e8;
width: 600px;
display: block;
margin: 0 auto;
padding: 5px;
font-size: 9pt;
height: auto;
}
.slide
{
margin: 0;
padding: 0;
width: 600px;
border-top: solid 4px gray;
margin: 0 auto;
}
.btn-slide
{
background: gray;
text-align: center;
width: 120px;
height: 30px;
padding: 10px 10px 0 0;
margin: 0 auto;
display: block;
color: #fff;
text-decoration: none;
}
</style>
<script type="text/javascript">
function showdiv() {
document.getElementById("hpn").style.display = "block";
// document.getElementById("pn").style.height='80px';
document.getElementById("strHref").href = "javascript:hidediv();";
document.getElementById("strHref").innerHTML = "收起-";
}
function hidediv() {
document.getElementById("hpn").style.display = "none";
// document.getElementById("pn").style.height='60px';
document.getElementById("strHref").href = "javascript:showdiv();";
document.getElementById("strHref").innerHTML = "更多选项+";
}
</script>
</head>
<body>
<div>
<div id="pn">
<p>
手机 - 商品筛选</p>
<p>
网络: 移动4G(TD-LTE ) 联通4G(TD-LTE) 联通3G(WCDMA)
</p>
<div id="hpn" style="display: none">
<p>
价格: 5000以上 4000-4999 3000-3999 2000-2999
</p>
<p>
特点: JDPhone计划 "0"元购机 防水 长待机 1080P全高清屏
</p>
</div>
</div>
<p class="slide">
<a href="javascript:showdiv();" id="strHref" class="btn-slide">更多选项+</a></p>
</div>
</body>
</html>
上面这样调用可以执行showdiv()
但是用onclick如下就不能执行,这是为什么呢?求解.
<!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=utf-8" />
<title></title>
<style type="text/css">
body
{
margin: 0 auto;
padding: 0;
}
a:focus
{
outline: none;
}
#pn
{
background: #e8e8e8;
width: 600px;
display: block;
margin: 0 auto;
padding: 5px;
font-size: 9pt;
height: auto;
}
.slide
{
margin: 0;
padding: 0;
width: 600px;
border-top: solid 4px gray;
margin: 0 auto;
}
.btn-slide
{
background: gray;
text-align: center;
width: 120px;
height: 30px;
padding: 10px 10px 0 0;
margin: 0 auto;
display: block;
color: #fff;
text-decoration: none;
}
</style>
<script type="text/javascript">
function showdiv() {
document.getElementById("hpn").style.display = "block";
// document.getElementById("pn").style.height='80px';
document.getElementById("strHref").href = "javascript:hidediv();";
document.getElementById("strHref").innerHTML = "收起-";
}
function hidediv() {
document.getElementById("hpn").style.display = "none";
// document.getElementById("pn").style.height='60px';
document.getElementById("strHref").href = "javascript:showdiv();";
document.getElementById("strHref").innerHTML = "更多选项+";
}
</script>
</head>
<body>
<div>
<div id="pn">
<p>
手机 - 商品筛选</p>
<p>
网络: 移动4G(TD-LTE ) 联通4G(TD-LTE) 联通3G(WCDMA)
</p>
<div id="hpn" style="display: none">
<p>
价格: 5000以上 4000-4999 3000-3999 2000-2999
</p>
<p>
特点: JDPhone计划 "0"元购机 防水 长待机 1080P全高清屏
</p>
</div>
</div>
<p class="slide">
<a href="#" id="strHref" class="btn-slide" onclick="showdiv()">更多选项+</a></p>
</div>
</body>
</html>
...全文
相关推荐
详解a-href=#与-a-href=javascript-void(0)-的区别.doc
详解a-href=#与-a-href=javascript-void(0)-的区别.doc
a标签的学习总结
总结的很多关于a标签学习和运用中的细节,值得大家好好看一下
a标签href属性与onclick事件使用实例
a标签主要用来实现页面跳转,可以通过href属性实现,也可以在onclick事件里实现,下面为大家简要介绍下其具体的使用
A标签中通过href和onclick传递的this对象实现思路
在blog的后台管理中允许为一个分类添加一个地址,但是不好添加onclick事件。想传递当前对象给一个函数,于是就将这个URL写成”[removed]shoControlSidebar(this)”,可是结果发现这并不可行,传递过去的参数是一个对象,但是却得不到任何其他信息。我想得到的是innerText,而这个this并非指向它所在的A标签。 这是<a>和<a>不同的地方。 当使用onc
jquery A标签onclick事件
jquery下A标签onclick事件的处理,看看看看看看。


