js 常用方法

1、获得select选中的文本 或 value onchange 事件

function czSelect(dom,vt){
  if(vt==="text"){
  return txt=dom.options[dom.options.selectedIndex].text;
  }if(vt==="value"){
  return txt=dom.options[dom.options.selectedIndex].value;
  }
}
2、checkbox选中个数
function czCheckbox(dom){
  var checked_counts = 0;
  for(var i=0;i<dom.length;i++){
  if(dom[i].checked) {
  checked_counts++;
   }
  }
  return checked_counts;
}
3、获得radio的文本或value
function czRadio(dom,vt){
  for(var i=0;i<dom.length;i++){
  if(dom[i].checked){
  if(vt==="text"){
  return dom[i].text;
  }if(vt==="value"){
  return dom[i].value;
    }
  }
  }
}

4、超链接点击后不被带到目标窗口

      <a href="http://www.baidu.com" title="百度" onclick="helloWord();return false;">百度</a>

      return false:表示onclick事件处理函数认为这个链接没被点击

原文地址:https://www.cnblogs.com/jalja/p/4496738.html