Jquery method to determine whether it is a string: 1. Determine it as a string type, the code is [alert((typeof str=='string')&&str.constructor==String)]; 2. Determine it as Array type, the code is [alert((typeof..].
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer, the The method is applicable to all brands of computers.
Recommendation: jquery video tutorial
jquery method to determine whether it is a string:
1. Determine whether it is a string type
var str="ss"; alert((typeof str=='string')&&str.constructor==String)
2. Determine whether it is an array type
var obj=[0]; alert((typeof obj=='object')&&obj.constructor==Array)
Method 2
function isString(obj){ //判断对象是否是字符串 return Object.prototype.toString.call(obj) === "[object String]"; } 验证: var str1 = 'abc'; var str2 = new String('abc'); typeof str1; //"string" typeof str2; //"object" Object.prototype.toString.call(str1); //"[object String]" Object.prototype.toString.call(str2); //"[object String]"
3. Determine whether it is a numeric type
var str=547.97; alert((typeof str=='number')&&str.constructor==Number)
4. Determine whether it is a date type
var obj =new Date(); alert((typeof obj=='object')&&obj.constructor==Date)
5. Determine whether it is a function
var obj = function test(){}; alert((typeof obj=='function')&&obj.constructor==Function)
Related free learning recommendations: javascript(Video)
The above is the detailed content of How to determine if jquery is a string. For more information, please follow other related articles on the PHP Chinese website!