zoukankan      html  css  js  c++  java
  • 常用Javascript集锦【不定期更新】

    怎样用javascript删除某个HEML标签

    document.getElementById(id).parentNode.removeChild(document.getElementById(id));
    var br=document.getElementsByClassName('ace_layer ace_text-layer')[0];
    document.getElementsByClassName('ace_content')[0].removeChild(br);

    javascript之html元素文本输出

    document.getElementById("demo").innerHTML="hello world";

    怎样通过标签为元素添加属性

    document.getElementsByTagName("body")[0].setAttribute("type","text")

    怎样移除元素某个属性

    document.getElementsByClassName('marketingPlanLeft')[0].removeAttribute('style');

    设置元素可见

    document.getElementsByClassName('goOnShopping')[0].style.display='block';
    document.getElementById('').style.diplay='block';

    利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位。

     
      方法一:

    document.getElementById("EleId").style.visibility="hidden";
    document.getElementById("EleId").style.visibility="visible";

      利用上述方法实现隐藏后,页面的位置还被控件占用,显示空白。
      方法二:

    document.getElementById("EleId").style.display="none";
    document.getElementById("EleId").style.display="inline";

      利用上述方法实现隐藏后,页面的位置不被占用。

    onlick事件跳转到其他页面/跳转到指定url

    ☆如果是本页显示可以直接用location,方法如下:

    <input type="submit" id="su" value="submit" onclick="window.location='http://www.cnblogs.com/JuneZhang/archive/2010/11/25/1887575.html'">
    <input type="submit" id="su" value="submit" onclick="location='http://www.cnblogs.com/JuneZhang/archive/2010/11/25/1887575.html'">
    <input type="submit" id="su" value="submit" onclick="window.location.href='http://www.cnblogs.com/JuneZhang/archive/2010/11/25/1887575.html'">
      ①onclick="javascript:window.location.href='URL'"
      ②onclick="location='URL'"
      ③onclick="window.location.href='URL?id=11'"
    ☆如果页面中有frame可以将在location前面添加top.mainframe.frames['right_frame'].location

    onlick事件关闭当前窗口

    <input type="submit" id="su" value="submit" onclick="javascript:window.close()">
  • 相关阅读:
    jdbc和DBeaver客户端连接oracle很慢,初始化连接成功后速度正常
    centos7中vncserver连接失败
    postgres数据库建库、修改owner
    nested exception is org.apache.ibatis.binding.BindingException:
    postgresql导出表insert方式数据
    解决ecllipse注释模板不生效问题
    postgresql 修改表属性,包括新增、修改、删除列
    ssh本机可登陆远端服务器,但远端服务器无法登陆本机
    linux源码安装后,设置动态库路径和环境变量
    valgrind跟踪调试动态库*.so
  • 原文地址:https://www.cnblogs.com/longronglang/p/7562881.html
Copyright © 2011-2022 走看看