现在我使用toggleMonotoneMode切换css类,但我想添加允许用户选择颜色的功能。
现有的css:
.monotone [id^='_'] {
fill: #339933;
}
现有的js:
var toggleMonotoneMode = function() {
helpers.toggleClass(build, 'monotone');
};
新的html5功能:
<input id="monotonecolor" type="color" value="#339933" />
一半完成javascript:
var monotoneSelect = document.getElementById('monotonecolor');
monotoneSelect.value = ?
monotoneSelect.addEventListener('click', function() { helpers.addClass(build, 'monotone') }, false);
编辑:
尝试1:不起作用......
var toggleMonotoneMode = function() {
monotoneSelect.value = build.style.fill;
};
monotoneSelect.addEventListener('click', function() { monotoneSelect.value = build.style.fill; }, false);
尝试2:关闭......
var buildfill = document.querySelectorAll('build[id^="_"]')
var toggleMonotoneMode = function() {
buildfill = monotoneSelect.value;
};
尝试3:我意识到自己犯了一个错误
var buildfill = document.querySelectorAll('build[id^="_"]')
var toggleMonotoneMode = function() {
buildfill.style.fill = monotoneSelect.value;
};
monotoneSelect.addEventListener('click', function() { buildfill.style.fill = monotoneSelect.value; }, false);
嗯...仍然没有获得[id ^ =&#34; _&#34;]的匹配(返回undefined),但这可能超出了这个问题的范围。
我怎么做这个切换呢?
var toggleMonotoneMode = function() {
buildfill.style.fill = monotoneSelect.value;
};