我想使用javascript更改与单选按钮关联的文本样式 [英] I Want to change the style of the text associated with a radio button using javascript

查看:53
本文介绍了我想使用javascript更改与单选按钮关联的文本样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如问题中所述

i想要改变与固定单选按钮相关联的文本的样式或特别颜色

i知道如何使用标签,我可以更改特定单选按钮的文本使用

As told in the question
i want to change the style or particularly color of the text associated with a fixed radio button
i know how to use label and i can change the text of a particular radio button using

document.getElementById('ques29').firstChild.nodeValue

for <input type="radio" name = "q30" value="D"><label id="ques29">(D) work function</label>





所以任何人都可以指导我如何更改文本的颜色



so can anyone guide me on how to change the color of the text

推荐答案

Step1:添加以下样式

Step1: Add below style
<style>
.mystyle {
  background-color: coral;
  font-size: 25px;
  color: green;
}
</style>



第2步:在下面添加javascript代码


Step2: Add below javascript code

<script>
var ele = document.getElementById('ques29');
ele.setAttribute('class', 'mystyle');
</script></script>





注意:这里是HTML控制单选按钮的'ques29'ID。您可以实现相同的任何HTML控件。



Note: Here 'ques29' ID of HTML Control radio button. You can implement the same any HTML control.


除了解决方案1:jQuery中的库用户可以非常方便地实现这些:

http://api.jquery.com/category/css [ ^ ],

http ://api.jquery.com/addClass [ ^ ] ,

http://api.jquery.com/removeClass/ [ ^ ],

http://api.jquery.com/toggleClass/ [ ^ ]。



如果您需要学习jQuery(强烈推荐),请参阅:

<啊ref =http://en.wikipedia.org/wiki/JQuery> http://en.wikipedia.org/wiki/JQuery ,

http://jquery.com

http:// learn.jquery.com

http://learn.jquery.com / using-jquery-core

http:// learn.jquery.com/about-jquery/how-jquery-works (从这里开始)。



如果你想改变大小无线电底部本身,它是图形元素,您需要使用图像模拟此输入元素,通过 img 元素,更改其 src 属性动态,以响应输入事件等。许多作者多次这样做,也不是那么困难。



-SA
In addition to Solution 1: such things are implemented very conveniently for the library users in jQuery:
http://api.jquery.com/category/css[^],
http://api.jquery.com/addClass[^],
http://api.jquery.com/removeClass/[^],
http://api.jquery.com/toggleClass/[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery,
http://jquery.com,
http://learn.jquery.com,
http://learn.jquery.com/using-jquery-core,
http://learn.jquery.com/about-jquery/how-jquery-works (start from here).

In case you want to change the size of the radio bottom itself, it graphics elements, you would need to simulate this input element using the images, via the img element, change its src attribute in JavaScript dynamically, in response to input events and so on. This was done by many authors many times, is also not so difficult.

—SA


这篇关于我想使用javascript更改与单选按钮关联的文本样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆