js 重新加载html代码,如何以编程方式更改HTML后重新加载js模块?

我是AngularJS的新用户,而我正在使用AngularJS制作滑块 tag this sample

我想在点击按钮后向HTML添加另一个滑块。

这是我更改HTML部分的方式

Click here for Hipster Ipsum.

Bespoke aesthetic Bushwick craft beer. Qui aesthetic butcher, cardigan ex scenester Neutra American Apparel mumblecore.

Add slider Slider

我的Javasciprt代码现在看起来像这样

angular.module('angularSlideables', [])

.directive('slideable', function () {

return {

restrict:'C',

compile: function (element, attr) {

// wrap tag

var contents = element.html();

element.html('

' + contents + '
');

return function postLink(scope, element, attrs) {

// default properties

attrs.duration = (!attrs.duration) ? '1s' : attrs.duration;

attrs.easing = (!attrs.easing) ? 'ease-in-out' : attrs.easing;

element.css({

'overflow': 'hidden',

'height': '0px',

'transitionProperty': 'height',

'transitionDuration': attrs.duration,

'transitionTimingFunction': attrs.easing

});

};

}

};

})

.directive('slideToggle', function() {

return {

restrict: 'A',

link: function(scope, element, attrs) {

var target = document.querySelector(attrs.slideToggle);

attrs.expanded = false;

element.bind('click', function() {

var content = target.querySelector('.slideable_content');

if(!attrs.expanded) {

content.style.border = '1px solid rgba(0,0,0,0)';

var y = content.clientHeight;

content.style.border = 0;

target.style.height = y + 'px';

} else {

target.style.height = '0px';

}

attrs.expanded = !attrs.expanded;

});

}

}

});

function goAdd() {

var ht="

Another Slider

hi my name is Alex

";

document.getElementById('slideholder').innerHTML=ht;

}

虽然我制作了确切的代码,但我的滑块无法正常工作。我认为这是因为我添加更多HTML代码后模块无法重新加载。所以我的问题是如何在点击按钮后重新加载javascript模块?

如果它有任何区别,我将在我的Cordova项目中使用此代码来使用ionic安卓应用。

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值