1. //js 判断iPhone|iPad|iPod  
  2. if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {  
  3.     alert(navigator.userAgent);  
  4. };  

定义和用法

test() 方法用于检测一个字符串是否匹配某个模式.

语法

RegExpObject.test(string)
参数 描述
string 必需。要检测的字符串。

返回值

如果字符串 string 中含有与 RegExpObject 匹配的文本,则返回 true,否则返回 false。

说明

调用 RegExp 对象 r 的 test() 方法,并为它传递字符串 s,与这个表示式是等价的:(r.exec(s) != null)。

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-07-10
  • 2021-12-03
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-06-01
  • 2021-11-27
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案