AngularJS 的用法
首先在html中导入Angularjs
<script type="text/javascript" src="js/angular.min.js"></script>
在html中,放置两个文本:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="admin" ng-controller="modify">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/angular.min.js"></script>
</head>
<body>
<input type="text" id="name" name="name" rows="10" cols="20" ng-keypress="myKeypress($event)" />
<input type="text" id="address" name="address" rows="10" cols="20" />
</body>
<script type="text/javascript" src="modify.js"></script>
</html>
最后modify.js代码中处理回车事件:
var app = angular.module('admin', []);
app.controller('order', function($scope, $http) {
$scope.myKeypress = function(e){
var keycode = window.event?e.keyCode:e.which;
if(keycode == 13){
document.getElementById("address").focus();
}
};
JQuery 的用法
在html中,放置几个文本
<input type="text" id="name1" name="name" onkeypress="EnterPress(event, 0, 1)" onkeydown="EnterPress()" />
<input type="text" id="address1" name="address" onkeypress="EnterPress(event, 1, 1)" onkeydown="EnterPress()" />
<input type="text" id="name2" name="name" onkeypress="EnterPress(event, 0, 2)" onkeydown="EnterPress()" />
<input type="text" id="address2" name="address" onkeypress="EnterPress(event, 1, 2)" onkeydown="EnterPress()" />
当前文本聚焦时,回车光标移动到下一个文本框中
js处理:
function EnterPress(e, type, nameId){ //传入 event
var e = e || window.event;
if(e.keyCode == 13){
if (type == 0) {
document.getElementById("address" + nameId).focus();
} else {
var a = parseInt(nameId);
a += 1;
document.getElementById("name" + a).focus();
}
}
}
网友评论