How to get input type using jquery?

后端 未结 11 1815
猫巷女王i
猫巷女王i 2020-11-28 02:17

I have a page where the input type always varies, and I need to get the values depending on the input type. So if the type is a radio, I need to get which is checked, and if

11条回答
  •  情歌与酒
    2020-11-28 02:38

    GetValue = function(id) {
      var tag = this.tagName;
      var type = this.attr("type");
    
      if (tag == "input" && (type == "checkbox" || type == "radio"))
        return this.is(":checked");
    
      return this.val();
    };
    

提交回复
热议问题