Javascript 选中复选框时将文本更改为正常

Javascript 选中复选框时将文本更改为正常,javascript,html,css,Javascript,Html,Css,我不熟悉CSS和JavaScript,我尝试在按下复选框时将文本从复选框更改为普通文本,但我没有成功。。。 开始时,文本包含一些粗体字,但单击后,所有短语都应设置为字体大小:正常 <FORM> <input type="checkbox" name="adresa1 onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <B>Subiectbold daca email nec

我不熟悉CSS和JavaScript,我尝试在按下复选框时将文本从复选框更改为普通文本,但我没有成功。。。 开始时,文本包含一些粗体字,但单击后,所有短语都应设置为字体大小:正常

<FORM>

        <input type="checkbox" name="adresa1 onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <B>Subiectbold daca email necitit</B> - data primire <BR>  
        <input type="checkbox" name="adresa" > joey@gmail.com - <B>Subiectbold daca email necitit</B> - data primire </a><BR>
        <input type="checkbox" name="adresa" > adresa@expeditor.com - <B>Subiectbold daca email necitit</B> - data primire <BR>

</FORM>


使用
:checked
伪类,您可以很容易地将CSS与相邻的同级组合符(
+
)一起使用:

input[type=checkbox]:checked + b {
  font-weight: normal;
}
input[type=checkbox]:选中+b{
字体大小:正常;
}

adresa@expeditor.com -
子条款BOLD daca电子邮件必要-数据原件

joey@gmail.com - 子条款BOLD daca电子邮件必要-数据原件
adresa@expeditor.com - 子条款BOLD daca电子邮件必要-数据原件

您可以很容易地使用CSS实现这一点,使用
:checked
伪类,使用相邻的兄弟组合符(
+
):

input[type=checkbox]:checked + b {
  font-weight: normal;
}
input[type=checkbox]:选中+b{
字体大小:正常;
}

adresa@expeditor.com -
子条款BOLD daca电子邮件必要-数据原件

joey@gmail.com - 子条款BOLD daca电子邮件必要-数据原件
adresa@expeditor.com - 子条款BOLD daca电子邮件必要-数据原件

您可以很容易地使用CSS实现这一点,使用
:checked
伪类,使用相邻的兄弟组合符(
+
):

input[type=checkbox]:checked + b {
  font-weight: normal;
}
input[type=checkbox]:选中+b{
字体大小:正常;
}

adresa@expeditor.com -
子条款BOLD daca电子邮件必要-数据原件

joey@gmail.com - 子条款BOLD daca电子邮件必要-数据原件
adresa@expeditor.com - 子条款BOLD daca电子邮件必要-数据原件

您可以很容易地使用CSS实现这一点,使用
:checked
伪类,使用相邻的兄弟组合符(
+
):

input[type=checkbox]:checked + b {
  font-weight: normal;
}
input[type=checkbox]:选中+b{
字体大小:正常;
}

adresa@expeditor.com -
子条款BOLD daca电子邮件必要-数据原件

joey@gmail.com - 子条款BOLD daca电子邮件必要-数据原件
adresa@expeditor.com - 子条款BOLD daca电子邮件必要-数据原件

既然你是一个乞丐,正如你所说的,你首先应该尝试这样做:

<form>
        <input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label id="lbl1">Subiectbold daca email necitit</label> -data primire <BR> 
</form>


<script>
function GetBold(current)
{
    var checkB= document.getElementById(current.id);
    var labelText = document.getElementById("lbl1");

if(checkB.checked)
    labelText.style.fontWeight = 'bold';
else
        labelText.style.fontWeight = 'normal';
 }
</script>
<style>
.normal{
font-weight:normal;
}
.bold{
font-weight:bold;
}
</style>

adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件
函数GetBold(当前) { var checkB=document.getElementById(当前的.id); var labelText=document.getElementById(“lbl1”); 如果(选中b.选中) labelText.style.fontWeight='bold'; 其他的 labelText.style.fontWeight='normal'; }
然后,当您了解如何在CSS中创建两个类时,因为用html(使用标记)装饰文本并不好,更好的选择是创建两个类,如下所示:

<form>
        <input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label id="lbl1">Subiectbold daca email necitit</label> -data primire <BR> 
</form>


<script>
function GetBold(current)
{
    var checkB= document.getElementById(current.id);
    var labelText = document.getElementById("lbl1");

if(checkB.checked)
    labelText.style.fontWeight = 'bold';
else
        labelText.style.fontWeight = 'normal';
 }
</script>
<style>
.normal{
font-weight:normal;
}
.bold{
font-weight:bold;
}
</style>

.正常{
字体大小:正常;
}
.bold{
字体大小:粗体;
}
然后在javascript中获取所有要更改的元素(使用getElementsByTagName):

函数GetBold(当前)
{
var checkB=document.getElementById(当前的.id);
var array=document.getElementsByTagName(“标签”);//从html获取所有标签标签
对于(var i=0;i
要更改的所有文本都应位于标记标签中:

<input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label class="bold">Subiectbold daca email necitit</label> - data primire <BR>  
    <input type="checkbox" > joey@gmail.com - <label class="bold">Subiectbold daca email necitit</label> - data primire <BR> 
    <input type="checkbox" name="adresa"> adresa@expeditor.com - <label class="bold">Subiectbold daca email necitit</label> - data primire <BR> 
adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件
joey@gmail.com-必要的子条款BOLD daca电子邮件-数据原件
adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件

请注意,有一个类名“bold”而不是tag,同样的类名将在上面提到的javascript函数中更改

,因为您是一个乞丐,正如您所说的,您首先应该尝试这样做:

<form>
        <input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label id="lbl1">Subiectbold daca email necitit</label> -data primire <BR> 
</form>


<script>
function GetBold(current)
{
    var checkB= document.getElementById(current.id);
    var labelText = document.getElementById("lbl1");

if(checkB.checked)
    labelText.style.fontWeight = 'bold';
else
        labelText.style.fontWeight = 'normal';
 }
</script>
<style>
.normal{
font-weight:normal;
}
.bold{
font-weight:bold;
}
</style>

adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件
函数GetBold(当前) { var checkB=document.getElementById(当前的.id); var labelText=document.getElementById(“lbl1”); 如果(选中b.选中) labelText.style.fontWeight='bold'; 其他的 labelText.style.fontWeight='normal'; }
然后,当您了解如何在CSS中创建两个类时,因为用html(使用标记)装饰文本并不好,更好的选择是创建两个类,如下所示:

<form>
        <input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label id="lbl1">Subiectbold daca email necitit</label> -data primire <BR> 
</form>


<script>
function GetBold(current)
{
    var checkB= document.getElementById(current.id);
    var labelText = document.getElementById("lbl1");

if(checkB.checked)
    labelText.style.fontWeight = 'bold';
else
        labelText.style.fontWeight = 'normal';
 }
</script>
<style>
.normal{
font-weight:normal;
}
.bold{
font-weight:bold;
}
</style>

.正常{
字体大小:正常;
}
.bold{
字体大小:粗体;
}
然后在javascript中获取所有要更改的元素(使用getElementsByTagName):

函数GetBold(当前)
{
var checkB=document.getElementById(当前的.id);
var array=document.getElementsByTagName(“标签”);//从html获取所有标签标签
对于(var i=0;i
要更改的所有文本都应位于标记标签中:

<input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label class="bold">Subiectbold daca email necitit</label> - data primire <BR>  
    <input type="checkbox" > joey@gmail.com - <label class="bold">Subiectbold daca email necitit</label> - data primire <BR> 
    <input type="checkbox" name="adresa"> adresa@expeditor.com - <label class="bold">Subiectbold daca email necitit</label> - data primire <BR> 
adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件
joey@gmail.com-必要的子条款BOLD daca电子邮件-数据原件
adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件

请注意,有一个类名“bold”而不是tag,同样的类名将在上面提到的javascript函数中更改

,因为您是一个乞丐,正如您所说的,您首先应该尝试这样做:

<form>
        <input type="checkbox" name="adresa1" onClick="GetBold(this);" id="mail1"> adresa@expeditor.com - <label id="lbl1">Subiectbold daca email necitit</label> -data primire <BR> 
</form>


<script>
function GetBold(current)
{
    var checkB= document.getElementById(current.id);
    var labelText = document.getElementById("lbl1");

if(checkB.checked)
    labelText.style.fontWeight = 'bold';
else
        labelText.style.fontWeight = 'normal';
 }
</script>
<style>
.normal{
font-weight:normal;
}
.bold{
font-weight:bold;
}
</style>

adresa@expeditor.com-必要的子条款BOLD daca电子邮件-数据原件
函数GetBold(当前) { var checkB=document.getElementById(当前的.id); var labelText=document.getElementById(“lbl1”); 如果(选中b.选中) labelText.style.fontWeight='bold'; 其他的 labelText.style.fontWeight='normal'; }
然后,当您了解如何在CSS中创建两个类时,因为用html(使用标记)装饰文本并不好,更好的选择是创建两个类