【问题标题】:how can i migrate jquery to javascript?如何将 jquery 迁移到 javascript?
【发布时间】:2018-04-17 16:38:08
【问题描述】:

大家好,我正在研究 Angular.js,我想在调整浏览器大小时动态调整 div 的大小。我在JSFiddle上创建了这位先生的代码http://jsfiddle.net/jaredwilli/SfJ8c/,我把它捡起来改了。我不想使用任何 jQuery 代码。

我试着像这样迁移它。

myApp.directive('resize', function ($window) {
  return function (scope, element) {
    var w = $window;

    scope.getWindowDimensions = function () {
      return {
        'h': w.innerHeight
      };
    };
    scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {
      scope.windowHeight = newValue.h;

      scope.style = function () {
        return {
          'height': (newValue.h - 245) + 'px',
        };
      };

    }, true);

    w.bind('resize', function () {
      scope.$apply();
    });
  }
}) 

它在页面重新加载时触发,并且 div 改变了高度,但它是 w w.bind 不是一个函数。有人可以帮我迁移吗?

【问题讨论】:

标签: javascript jquery angularjs


【解决方案1】:

我认为下面的代码块应该可以工作

var jquery = document.createElement('script');
jquery.src = 'https://code.jquery.com/jquery-1.11.3.js';
jquery.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(jquery);

【讨论】:

  • 好的,我知道了,你可以添加到你的js文件中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-29
  • 2022-01-04
  • 1970-01-01
  • 2023-03-30
  • 2021-12-15
  • 2021-07-19
  • 2019-05-15
相关资源
最近更新 更多