JavaScript

By admin, 8 二月, 2015

 

 

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

标签

By admin, 8 二月, 2015

 

// 类似于HTTP跳转

window.location.replace("http://howto.eguidedog.net");

 

// 类似于点击一个链接

window.location.href = "http://howto.eguidedog.net";

标签

By admin, 8 二月, 2015

有时候,我们想通过Javascript/jQuery获取URL中的参数值,例如想获取下面地址中的q值(keyword):

http://example.com/?q=keyword&action=query

可以通过下面函数实现:

 

标签

By admin, 6 二月, 2015

drupal_add_js和drupal_add_css已经不可用了。可以通过下面方法添加JS和CSS:

假设自定义的模块名称是foobar,在模块的目录下创建文件foobar.libraries.yml(模块的目录应该是modules/foobar),内容如下:

 

foobar:

  version: 1.x

    css:

      theme: css/foo.css: {}

    js: js/bar.js: {}

    dependencies: - core/jquery

然后在模块的目录下创建js/bar.js和css/foo.css就可以了。jquery不再是Drupal 8模块加载的JS,所以有需要就加上dependencies。

在return form的时候声明加载的库: