我不确定我是否明白你的意思,但如果 sec-intro 是一个 javascript 变量,你可以试试这个:
<script type="text/javascript">
$( document ).ready(function() {
jQuery('#intro').load( 'tpl/sec-intro-' + sec-intro + '.html' );
});
</script>
但我认为您对使用 {{var}} 的 AngularJS 表示法感到困惑。
编辑:
嗯,首先变量名不能有连字符,所以你需要更改该名称。
第二件事,你应该在控制器的代码中声明这个函数。我做了一个小角度应用程序,即代码:
脚本:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.secintro = '01';
$scope.loadFunction = function(){
jQuery('#intro').load('tpl/sec-intro-' + $scope.secintro + '.html');
};
$scope.loadFunction();
});
HTML:
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="jquery" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script data-require="angular.js@1.0.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js" data-semver="1.0.8"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
</body>
</html>
然后你可以使用 loadFunction 作为 angularJS 函数,即:ng-init="loadFunction();"
<body ng-controller="MainCtrl" ng-init="loadFunction();">
</body>
这将在控制器准备好时执行该函数,因此您不需要$scope.loadFunction(); 初始化。
Here is the plunker 只需在控制台中打印正确的字符串。
我希望这最终对你有用。