我必须动态设置边距到元素。之前它是通过以下方式完成的。
var starLink = star.createChild({
tag: 'a',
html: this.values[i],
href: 'javascript:void',
title: this.showTitles ? this.titles[i] : ''
});
// Prepare division settings
if(this.split) {
var odd = (i % this.split);
star.setWidth(sw);
starLink.setStyle('margin-left', '-' + (odd * sw) + 'px');
}
但现在我改变了我的代码如下。我如何设置保证金?
var starLink = document.createElement('a');
starLink.href = 'javascript:void';
starLink.title = this.showTitles ? this.titles[i] : '';
starLink.innerHTML = this.values[i];
star.appendChild(starLink);
// Prepare division settings
if(this.split) {
var odd = (i % this.split);
star.setWidth(sw);
starLink.setStyle('margin-left', '-' + (odd * sw) + 'px');
}
答案 0 :(得分:2)
starLink.style.marginLeft = '10px的' 要么 starLink.style.margin =“0px 0px 0px”+ xOffset +“px”;
答案 1 :(得分:0)
怎么样
var starLink = document.createElement('a');
starLink.href = 'javascript:void';
starLink.title = this.showTitles ? this.titles[i] : '';
starLink.innerHTML = this.values[i];
star.appendChild(starLink);
// Prepare division settings
if(this.split) {
var odd = (i % this.split);
star.setWidth(sw);
starLink.style.marginLeft = '-' + (odd * sw) + 'px';
}