小编Ele*_*ary的帖子

使用EJS或jQuery设置HTML标记的属性

在我的快速服务器上,我正在使用如下数据呈现页面:

app.get('/people/:personID', function (req, res) {
  res.render("people/profile", {person: req.person });
});
Run Code Online (Sandbox Code Playgroud)

在我的profile.ejs文件中,我可以访问ejs标签中的数据,如下所示: <p><%= person.name %></p>

我无法想象如何将html标签的属性更改为存储在此对象中的值.

这不起作用:<img id="my_img" src=<%= person.picture %> alt="">
或者:$("#my_img").attr("src", <%= person.picture %>);

此外,如果有更好的方法将此文档传递到html页面并访问它,我会全神贯注(或在这种情况下是眼睛).谢谢

html javascript jquery ejs express

10
推荐指数
1
解决办法
1万
查看次数

AngularJS切换用户选择的css主题

我从bootswatch下载了主题,我试图让用户切换主题.当切换主题时,所有bootstap css暂时消失,直到加载新主题.如何在加载css之前阻止更改或切换回默认主题,直到加载新主题为止?

index.ejs(头部)

<link rel="stylesheet" href="/external/bootstrap/css/bootstrap_yeti.min.css"
      ng-if="myTheme == ''">
<link rel="stylesheet" ng-href="/external/bootstrap/css/bootstrap_{{myTheme}}.min.css"
      ng-if="myTheme != ''">
Run Code Online (Sandbox Code Playgroud)

选择

<select class="form-control"
        id="theme"
        name="theme"
        ng-model="theme"
        ng-change="newTheme()">
  <option value="" disabled>Select Theme</option>
  <option ng-repeat="(key, val) in availableThemes" value="{{val}}">{{key}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

控制器索引

$scope.myTheme = '';
$rootScope.$watch('myTheme', function(value) {
  if (value != undefined) {
    $scope.myTheme = value;
  }
});
Run Code Online (Sandbox Code Playgroud)

控制器供选择

$scope.availableThemes = {
  Cerulean: 'cerulean',
  Cosmo:    'cosmo',
  Yeti:     'yeti'
};
$scope.newTheme = function() {
  console.log($scope.theme);
  if ($scope.theme != undefined) {
    $rootScope.myTheme = $scope.theme;
  }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!谢谢

html javascript css twitter-bootstrap angularjs

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

html ×2

javascript ×2

angularjs ×1

css ×1

ejs ×1

express ×1

jquery ×1

twitter-bootstrap ×1