我有两个盒子,可以通过onclick增加和减小尺寸。但现在我的超链接无效。
CODE:
function changeSize(id, weight, height){
var elem = document.getElementById(id);
if(elem.getAttribute('style')){
elem.removeAttribute('style');
} else {
elem.style.width = weight + 'px';
elem.style.height = height + 'px';
elem.style.fontSize = '30px';
}
}
var elems = document.getElementsByClassName('kaesten');
for(var i = 0; i < elems.length; i++){
elems[i].onclick = function(){
changeSize(this.id, 600, 600);
}
}
.kaesten{
width:240px;
height:300px;
background-color:darkgrey;
background-position:center;
background-repeat:no-repeat;
text-shadow:0px 0px 3px #000;
border: 5px solid #F0F8ff;
vertical-align:top;
text-shadow: 3px 3px 4px #777;
float:left;
margin-left:30px;
}
<div id="box1" class="kaesten" onclick="changeSize('standort', 600, 600); return false;">
<a href="www.google.de"> text </a>
</div>
<div id="box2" class="kaesten" onclick="changeSize('standort', 600, 600); return false;">
<a href="www.focus.de"> text </a>
</div>
问题:我在没有打开的onclick功能的情况下链接了一些内部网站点和办公室文档!如何使链接起作用并保持功能?
答案 0 :(得分:0)
在超链接//
href="//www.focus.de"
function changeSize(id, weight, height){
var elem = document.getElementById(id);
if(elem.getAttribute('style')){
elem.removeAttribute('style');
} else {
elem.style.width = weight + 'px';
elem.style.height = height + 'px';
elem.style.fontSize = '30px';
}
}
var elems = document.getElementsByClassName('kaesten');
for(var i = 0; i < elems.length; i++){
elems[i].onclick = function(){
changeSize(this.id, 600, 600);
}
}
.kaesten{
width:240px;
height:300px;
background-color:darkgrey;
background-position:center;
background-repeat:no-repeat;
text-shadow:0px 0px 3px #000;
border: 5px solid #F0F8ff;
vertical-align:top;
text-shadow: 3px 3px 4px #777;
float:left;
margin-left:30px;
}
<div id="box1" class="kaesten" onclick="changeSize('standort', 600, 600); return false;">
<a href="//www.google.de"> text </a>
</div>
<div id="box2" class="kaesten" onclick="changeSize('standort', 600, 600); return false;">
<a href="//www.focus.de"> text </a>
</div>
答案 1 :(得分:0)
我在我的主页上链接了一些内部网站点和办公室文档,并且遇到的问题是它们只打开了onclick功能!
现在我删除了返回false;在我的HTML中: 错误的代码:
<div id="box1" class="kaesten" onclick="changeSize('standort', 600, 600); return false;"> <a href="//www.google.de"> text </a> </div>
正确的代码:
<div id="box1" class="kaesten" onclick="changeSize('standort', 600, 600);"> <a href="//www.google.de"> text </a> </div>
现在我可以打开所有链接!