/static/css/sweeta" />
文档库 最新最全的文档下载
当前位置:文档库 › AngularJS+RequireJs实现动态加载JS和页面的方案研究

AngularJS+RequireJs实现动态加载JS和页面的方案研究

AngularJS+RequireJs实现动态加载JS和页面的方案研究
AngularJS+RequireJs实现动态加载JS和页面的方案研究

AngularJS+RequireJs实现动态加载JS和页面的方案研究

1、入口页面

存放地址:src/main/webapp/WEB-INF/view/workflow/workflow.jsp

[html] view plain copy 在CODE上查看代码片派生到我的代码片

这里是公共头部

这里是公共尾部

在上面引入了requirejs

2、app.js

[html] view plain copy 在CODE上查看代码片派生到我的代码片

require.config({

paths: {

"angular": "../angular/1.5.3/angular.min",

"angular-messages":"../angular/1.5.3/angular-messages.min",

"angular-locale_zh-cn":"../angular/1.5.3/angular-locale_zh-cn",

"angular-ui-router":

"../bower_components/angular-ui-router/release/angular-ui-router",

"angularAMD": "../bower_components/angularAMD/angularAMD",

"ngload": "../bower_components/angularAMD/ngload",

"sweetalert": "../sweetalert/sweetalert.min",

"uiBootstrap": "../angular-ui-bootstrap/1.2.4/ui-bootstrap-tpls-1.2.4.min",

"commonFunction":"../angularCommon/commonFunction",

"commonValueAndUrl":"../angularCommon/commonValueAndUrl",

"workFlowCommonModule":"../angularCommon/workFlowCommonModule"

},

shim: {

"angular": { exports: "angular" },

"workFlowCommonModule": ["angular"],

"angular-messages": ["angular"],

"angular-locale_zh-cn": ["angular"],

"commonValueAndUrl": ["commonFunction"],

"angular-ui-router": ["angular"],

"uiBootstrap": ["angular-ui-router"],

"angularAMD": ["angular"],

"ngload": ["angularAMD"]

}

});

define(["angular", "angularAMD", "angular-ui-router","sweetalert","uiBootstrap","angular-messages","angular-locale_zh-cn","com monFunction","commonValueAndUrl","workFlowCommonModule"], function (angular, angularAMD) {

var registerRoutes = function($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise("/home");

$stateProvider.state("home", angularAMD.route({

url: "/home",

templateUrl: "../static/js/workflow-view/home-view.js",

controllerUrl: "../static/js/workflow/home.js"

}))

.state("about", angularAMD.route({

url: "/about",

templateUrl: "../static/js/workflow-view/about-view.js",

controllerUrl: "../static/js/workflow/about.js"

}))

;

};

var app = angular.module("app", ["ui.router",'ui.bootstrap','ngMessages','commonModule']);

app.config(["$stateProvider", "$urlRouterProvider", registerRoutes]);

app.controller('baseCtrl',function($scope,$uibModal,sendAjaxFactory) {

$scope.baseClick = function () {

swal("测试按钮")

}

});

return angularAMD.bootstrap(app);

});

在这里引入了一些需要的模块,其中就一些模块是笔者我自己写的。有的是第三方插件的这里特别注意,由于SpringMVC会拦截.jsp结尾的文件。所以动态加载的页面笔者都写到js文件中。如上面的about-view.js和home-view.js.其要动态加载的js文件分别为about.js 和home.js。如果不使用SpringMVc。那么动态加载的页面就可以不用写到js文件中(笔者的工程中配置了拦截.jsp文件,不拦截.js文件)

3、动态加载的内容:

home.js

[html] view plain copy 在CODE上查看代码片派生到我的代码片

define(['app'], function(app)

{

app.controller('HomeViewController',

['$scope',function($scope) {

document.getElementById("test").onclick = function(){

swal($scope.title);

}

$scope.title = "Home Home Home Home";

}

]);

});

home-view.js

[html] view plain copy 在CODE上查看代码片派生到我的代码片

{{ title }}


温馨提示:带 *为必填项

id="merchantName" name = "merchantName" ng-model="merhantBaseInfo.merchantName" required>

ng-if="registerForm.merchantName.$touched">

用户名不能为空

商户类型不能为空

商户注册全名不能为空

所属行业不能为空

合作模式不能为空

"margin-left:50px;margin-right:-250px;">

合作区域不能为空

about.js:

[html] view plain copy 在CODE上查看代码片派生到我的代码片

define(['app'], function(app)

{

app.controller('AboutViewController',

['$scope',function($scope) {

document.getElementById("test").onclick = function(){

swal($scope.title);

}

$scope.title = "About About About About";

}

]);

});

其对应的页面内容about-view.js:

[html] view plain copy 在CODE上查看代码片派生到我的代码片

{{ title }}

温馨提示:带 *为必填项

已失效或终止的合同不能再修改内容!

已生效的合同只能修改部分内容!

商户不能为空

id="signDate" name = "signDate" ng-model="contractInfo.signDate" is-open="signDateOpened" ng-click = "signDateOpened = true" datepicker-options="dateOptions" current-text="今天" clear-text="清除" close-text="关闭" readonly ="readonly" date-format uib-datepicker-popup required>

合同签订日期不能为空

合同签署人不能为空

合同生效日期不能为空

合同失效日期不能为空

ng-if="registerForm.autoResignFlag.$touched">

到期自动续签不能为空

ng-if="registerForm.autoResignYears.$touched">

自动续签期限不能为空

ng-if="registerForm.specialInstallReq.$touched">

特殊分期要求不能为空

用Js脚本实现页面跳转

1. Javascript 返回上一页 history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forward()返回下一页 4. window.history.go(返回第几页,也可以使用访问过的URL) 例: 向上一页 response.Write("") response.Write("") 向上一页 页面跳转:onclick="window.location.href='list.aspx'" P.S. 小技巧(JS引用JS): Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand('Refresh') 6 window.navigate(location) 7 location.replace(location) 8 document.URL=location.href 自动刷新页面的方法: 1.页面自动刷新:把如下代码加入区域中 其中20指每隔20秒刷新一次页面.

JS关闭窗口弹出新窗口,关闭新窗口时,刷新父窗口,JS代码实现刷新网页,js实现弹出窗口代码收集集萃

经常上网的朋友可能到过这样一些网站,一进入首页立刻会弹出一个窗口,或者按一个链接或按钮弹出,通常在这个窗口里会显示一些注意事项、版权信息、警告、欢迎光顾之类的话或者作者想要特别提示的信息。其实制作这样的页面非常容易,只要往该页面的HTML里加入几段javascript代码即可实现。下面我就带你剖析它的奥秘。 【最基本的弹出窗口代码】 其实代码非常简单: 因为这是一段javascript代码,所以它们应该放在之间。是对一些版本低的浏览器起作用,在这些老浏览器中如果不支持javascript,不会将标签中的代码作为文本显示出来。 Window.open ('page.html')用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。 用单引号和双引号都可以,只是不要混用。 这一段代码可以加入HTML的任意位置,加入到和之间也可以,位置越靠前执行越早,尤其是页面代码较长时,又想使页面早点弹出就尽量往前放。 【经过设置后的弹出窗口】 下面再说一说弹出窗口外观的设置。只要再往上面的代码中加一点东西就可以了。 我们来定制这个弹出窗口的外观、尺寸大小、弹出位置以适应该页面的具体情况。

验证码: 看不清?

js弹出窗口总结6种弹窗方法

js弹出窗口总结6种弹窗方法 注: //关闭,父窗口弹出对话框,子窗口直接关闭 this.Response.Write(""); //关闭,父窗口和子窗口都不弹出对话框,直接关闭 this.Response.Write(""); //弹出窗口刷新当前页面width=200 height=200菜单。菜单栏,工具条,地址栏,状态栏全没有 this.Response.Write(""); //弹出窗口刷新当前页面 this.Response.Write(""); this.Response.Write(" "); //关闭当前子窗口,刷新父窗口 this.Response.Write(""); this.Response.Write(""); //子窗口刷新父窗口 this.Response.Write(""); this.Response.Write("");

『总结』JS常用方法与片段

『总结』JS常用方法与片段 1.javascript删除元素节点IE中有这样一个方 法:removeNode(),这个方法在IE下是好使的,但是在Firefox等标准浏览器中就会报错了removeNode is not defined,但是在核心JS中有一个操作DOM节点的方法叫:removeChild()。我们可以先去找到要删除节点的父节点,然后在父节点中运用removeChild来移除我们想移除的节点。我们可以定义一个方法叫removeElement:function removeElement(_element){ var _parentElement = _element.parentNode; if(_parentElement){ _parentElement.rem oveChild(_element); }}2.js sort方法根据数组中对象的某一个属性值进行升序或者降序排列/**数组根据数 组对象中的某个属性值进行排序的方法* 使用例子:newArray.sort(sortBy('number'),false) //表示根据number属性降序排列;若第二个参数不传递,默认表示升序排序* @param attr 排序的属性如number属性* @param rev true表示升序排列,false降序排序* */ sortBy: function(attr,rev){ //第二个参数没有传递默认升序排列if(rev == undefined){ rev = 1; }else{ rev = (rev) ? 1 : -1; }

return function(a,b){ a = a[attr]; b = b[attr]; if(a return rev * -1; } if(a > b){ return rev * 1; } return 0; } }3.charCodeAt()用法:charCodeAt() 方法可返回指定位置的字符的Unicode 编码。这个返回值是0 - 65535 之间的整数 语法:stringObject.charCodeAt(index) index参数必填,表示字符串中某个位置的数字,即字符在字符串中的下标。 注:字符串中第一个字符的下标是0。如果index 是负数,或大于等于字符串的长度,则charCodeAt() 返回NaN。例如:var str='Hello world!'document.write(str.charCodeAt(1))//结果:1014.js 页面刷新location.reload和location.replace的区别小结reload 方法,该方法强迫浏览器刷新当前页面。 语法:location.reload([bForceGet]) 参数:bForceGet,可选参数,默认为false,从客户端缓存里取当前页。true, 则以GET 方式,从服务端取最新的页面, 相当于客户端点击F5(“刷新”)replace 方法,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来

js实现页面跳转的详解

对于 window.location.href="login.jsp?backurl="+window.location.href; 第二种: 第三种: 第四种: 第五种: 2.javascript:指的是伪协议,是指用url的形式调用javascript 这句话相当于调用了javascript方法jump(“https://www.wendangku.net/doc/388234077.html,”); 3.另外摘自网友的描述: 关于js中"window.location.href"、"location.href"、 "parent.location.href"、"top.location.href"的用法 "window.location.href"、"location.href"是本页面跳转 "parent.location.href"是上一层页面跳转 "top.location.href"是最外层的页面跳转

JS脚本大全各种常用脚本

网页常用小技巧 1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键

no
可用于Table 2. 取消选取、防止复制 3. onpaste="return false" 不准粘贴 4. oncopy="return false;" oncut="return false;" 防止复制 5. IE地址栏前换成自己的图标 6. 可以在收藏夹中显示出你的图标 7. 关闭输入法 8. 永远都会带着框架 9. 防止被人frame 10. 网页将不能被另存为 11. 12.删除时确认 删除 13. 取得控件的绝对位置 //Javascript " ); } 第三: private void Button3_Click( object sender, System.EventArgs e ) { Response.AddHeader( "Refresh","0" ); } 第四: private void Button6_Click( object sender, System.EventArgs e ) { //Response.Write( " " ); } 第五:(需替换<>)