现在的位置: 首页 > 综合 > 正文

js中一个导致Safari浏览器崩溃的问题处理

2014年02月11日 ⁄ 综合 ⁄ 共 861字 ⁄ 字号 评论关闭

问题描述:
在所有的正文页中,点击文章页面下方的“推荐给朋友”文字链接,显示一文本框,点击该文本框下的“隐藏”按钮,Safari浏览器会崩溃


Safari浏览器崩溃原因:


<div id="sendfriend" style="display:none;">   
  <ul class="pasteLink">
    <li> <textarea id="area" cols="82" rows="3"></textarea>
<script>document.getElementById("area").value=tempstr;</script>
    你可以复制上方文本框的文字发给你的好友
    <input type="button" name="Submit1" value="复制" />
<input type="button" name="Submit2" value="隐藏" />
</li>
  </ul>
</div>
隐藏功能
function showHide(hideID,showID){
if(showID != null){
  if(document.getElementById(showID).style.display == "none"){  
   document.getElementById(showID).style.display = "block";
  }else{
   document.getElementById(showID).style.display = "none";
  }
}
if(hideID != null){
    document.getElementById(hideID).style.display = "none";     
}
document.getElementById("area").select();

}
标红的那段代码执行顺序导致的,既不能调用一个隐藏div中的子元素


解决方法:
document.getElementById("area").select();
把它移到if(showID != null){ 这行上面,既正常了

【上篇】
【下篇】

抱歉!评论已关闭.