使用 jscolor 更改文本颜色
Change text color with jscolor
我使用 http://jscolor.com/ 进行颜色操作,我需要能够更改此按钮中的文本颜色 <a href="#" id="button_cont" >Call to action</a>
。到目前为止,我只发现这段代码接近我的情况,但它也不适合我。
<script type="text/javascript">
function update(jscolor) {
$('#button_cont').css("color", "#" + jscolor);}
</script>
<input type="text" class="jscolor" onchange="update(this.jscolor);" />
<a href="#" id="button_cont" >Call to action</a>
您可以对元素调用 .style.color
并使用您需要的任何颜色将按钮更改为。每当我想更改 CSS 属性时,我总是调用 .style
。致电
document.getElementById("button_cont").style.color("red");
例如,如果您想将元素的颜色更改为红色。
您可以使用 onchange
回调来更新您的按钮文本颜色。
<body>
<input type="text" class="jscolor" onchange="update(this.jscolor);" />
<a href="#" id="button_cont">Call to action</a>
<script type="text/javascript">
function update(jscolor) {
$("#button_cont").css("color", "#" + jscolor);
// document.getElementById('button_cont').style.color = '#' + jscolor;
}
</script>
</body>
记得包含你的脚本导入
<script src="jscolor.js"></script>
当然还有jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
我使用 http://jscolor.com/ 进行颜色操作,我需要能够更改此按钮中的文本颜色 <a href="#" id="button_cont" >Call to action</a>
。到目前为止,我只发现这段代码接近我的情况,但它也不适合我。
<script type="text/javascript">
function update(jscolor) {
$('#button_cont').css("color", "#" + jscolor);}
</script>
<input type="text" class="jscolor" onchange="update(this.jscolor);" />
<a href="#" id="button_cont" >Call to action</a>
您可以对元素调用 .style.color
并使用您需要的任何颜色将按钮更改为。每当我想更改 CSS 属性时,我总是调用 .style
。致电
document.getElementById("button_cont").style.color("red");
例如,如果您想将元素的颜色更改为红色。
您可以使用 onchange
回调来更新您的按钮文本颜色。
<body>
<input type="text" class="jscolor" onchange="update(this.jscolor);" />
<a href="#" id="button_cont">Call to action</a>
<script type="text/javascript">
function update(jscolor) {
$("#button_cont").css("color", "#" + jscolor);
// document.getElementById('button_cont').style.color = '#' + jscolor;
}
</script>
</body>
记得包含你的脚本导入
<script src="jscolor.js"></script>
当然还有jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>