jquery 获取标签类型

jquery 获取标签类型,第1张

jquery获取标签名称:

jquery tagName prop()

如果想看某个元素是什么元素类型,只需要使用:

[object]attr("tagName")便可获取。

 select SOname as t_name, SCcolid as f_id,SCname as f_name,SClength as f_length,SCprec as f_prec,SCscale as f_scale,STname as f_type from         

             sysobjects   SO, -- 对象表  

             syscolumns   SC, -- 列名表  

             systypes     ST  -- 数据类型表   

             where SOid = SCid 

             and SOxtype = 'U'                   -- 类型U表示表,V表示视图  

             and SOstatus >= 0                   -- status >= 0 为非系统对象  

             and SCxtype = STxusertype

             and soname ='pz'

最后一列就是字段的类型,有问题可以追问

如何判断js中的数据类型:typeof、instanceof、 constructor、 prototype方法比较

如何判断js中的类型呢,先举几个例子:

var a = "iamstring";

var b = 222;

var c= [1,2,3];

var d = new Date();

var e =

function(){alert(111);};

var f =

function(){thisname="22";};

最常见的判断方法:typeof

alert(typeof a)

------------> string

alert(typeof b)

------------> number

alert(typeof c)

------------> object

alert(typeof d)

------------> object

alert(typeof e)

------------> function

alert(typeof f)

------------> function

其中typeof返回的类型都是字符串形式,需注意,例如:

alert(typeof a == "string")

-------------> true

alert(typeof a == String)

---------------> false

另外typeof

可以判断function的类型;在判断除Object类型的对象时比较方便。

判断已知对象类型的方法: instanceof

alert(c instanceof Array)

---------------> true

alert(d instanceof

Date)

alert(f instanceof Function)

------------> true

alert(f instanceof function)

------------> false

注意:instanceof

后面一定要是对象类型,并且大小写不能错,该方法适合一些条件选择或分支。

根据对象的constructor判断:

constructor

alert(cconstructor ===

Array) ----------> true

alert(dconstructor === Date)

-----------> true

alert(econstructor ===

Function) -------> true

注意: constructor 在类继承时会出错

eg,

function A(){};

function B(){};

Aprototype = new B(); //A继承自B

var aObj = new A();

alert(aobjconstructor === B) ----------->

true;

alert(aobjconstructor === A) ----------->

false;

而instanceof方法不会出现该问题,对象直接继承和间接继承的都会报true:

alert(aobj instanceof B) ---------------->

true;

alert(aobj instanceof B) ---------------->

true;

言归正传,解决construtor的问题通常是让对象的constructor手动指向自己:

aobjconstructor = A;

//将自己的类赋值给对象的constructor属性

alert(aobjconstructor === A) ----------->

true;

alert(aobjconstructor === B) ----------->

false; //基类不会报true了;

通用但很繁琐的方法: prototype

alert(ObjectprototypetoStringcall(a) === ‘[object String]’)

-------> true;

alert(ObjectprototypetoStringcall(b) === ‘[object Number]’)

-------> true;

alert(ObjectprototypetoStringcall(c) === ‘[object Array]’)

-------> true;

alert(ObjectprototypetoStringcall(d) === ‘[object Date]’)

-------> true;

alert(ObjectprototypetoStringcall(e) === ‘[object Function]’)

-------> true;

alert(ObjectprototypetoStringcall(f) === ‘[object Function]’)

-------> true;

大小写不能写错,比较麻烦,但胜在通用。

通常情况下用typeof

GetType()就可以,举个例子

List<T> lst=new List<T>();

object obj=lst;

//获取obj类型

SystemType otype = objGetType();

otype就是你需要的原来的类型了。

额,objGetType();应该获得的是List[T的类型],你可以通过类型名称抽取出T的类型再强制转换就可以了。或者直接对list的成员获取类型。

在上数据库实现技术的时候,老师提到了一个问题:如何在运行时获取一个变量的类型,这用C实现好像要大费周折。今天正好碰到一个问题想看看C++STL中的sort算法的实现,发现里面有个技巧可以很容易做到这一点。我就立刻自己做了一个实验。如下可以获取运行时变量的类型。

其中心思想就是,运用模板函数的重载,是什么类型的参数就去调用参数是那个类型的函数。这样就让编译器去自己识别,而编译器当然知道每个变量的类型。这让我想去探究那些我经常用到的STL算法的实现,如果你也经常使用,何不借此机会好好研究一下呢?我感觉至少有几个好处。

1、增强对C++语言的理解

2、增强程序的设计能力

3、增强算法分析与设计的能力#include<iostream>

using

namespace

std;void

PrintType(int

t){cout<<"int

type";}void

PrintType(char

t){cout<<"char

type";}void

PrintType(long

t){cout<<"long

type";

}template<typename

T>

inline

void

ValueType(T

t){PrintType(t);

}int

main(){int

a;char

c;ValueType(a);cout<<endl;

ValueType(c);cout<<endl;return

0;}

上例的功能很容易扩展,如果你向自己的项目添加了一个新的类型,那么只要重载一个PrintValue(

)即可。这仅仅是输出变量的类型,如果你还想再获取变量的类型的时候做更多的事情的话,显然也是很容易做到的。比如你想先获取变量的类型,这样之后才能确定分配给变量多少空间,那么这个也可以轻松实现,只需要改变PrintValue的功能即可。这里可以写一个int

PrintValue(YourType

t),她甚至应该有一个更好的名字比如int

Memory(Type

t)。

在不改变函数名的同时对上述函数稍加修改就可以实现输出传入参数应该分配的内存大小。

可以通过Class的name属性来查看数据类型,每一个对象都有一个Class,在java中一切皆对象,故能够通过如下方式来获取对象的类型: Date date = new Date();Systemoutprintln(dategetClass()getName()); //javautilDate

先获取Method对象

以下仅供参考

package comkiddtestzhidao;

import javalangreflectMethod;

/

  Hello world!

 

 /

public class Main {

    public static void main(String[] args) {

        Method method1 = null;

        Method method2 = null;

        try {

            method1 = ClassforName("comkiddtestzhidaoCat")getMethod("getName", (Class<>[]) null);

            method2 = ClassforName("comkiddtestzhidaoCat")getMethod("getChilds", (Class<>[]) null);

        } catch (NoSuchMethodException ex) {

            exprintStackTrace();

        } catch (SecurityException ex) {

            exprintStackTrace();

        } catch (ClassNotFoundException ex) {

            exprintStackTrace();

        }

        if (null != method1) {

            Systemoutprintln(method1getGenericReturnType()getTypeName());

        }

        if (null != method2) {

            Systemoutprintln(method2getGenericReturnType()getTypeName());

        }

    }

}

class Cat {

    private String name;

    private Cat[] childs;

    public String getName() {

        return name;

    }

    public void setName(String name) {

        thisname = name;

    }

    public Cat[] getChilds() {

        return childs;

    }

    public void setChilds(Cat[] childs) {

        thischilds = childs;

    }

}

以上就是关于jquery 获取标签类型全部的内容,包括:jquery 获取标签类型、SQL 中如何获取某一字段的类型、如何获取JS变量类型等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/10037718.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存