如何使用javascript在第一个复选框中存储第二个复选框ID [英] how to store second checkbox id in first checkbox using javascript

查看:58
本文介绍了如何使用javascript在第一个复选框中存储第二个复选框ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择第一个复选框然后自动选中第二个复选框。

如何使用javascript

解决方案

在第一个复选框中存储第二个复选框ID你可以这样做:



 <  输入    type   = 复选框    id   = 检查   >  <   / input  >  
< 输入 类型 = 复选框 id = Check1 >
< /输入 >



在JavaScript中:



  function  function1(){
document .getElementById( Check1)。checked = true ;
}


试试这个:

 <  !DOCTYPE     html  >  
< html >
< head >
< script >
function myfunction()
{
document.getElementById('checkbox2')。checked = document.getElementById('checkbox1')。checked
}
< / script >
< / head >
< body >
< 输入 type = 复选框 id = checkbox1 onclick = myfunction(); > Checkbox1
< 输入 < span class =code-attribute> type = 复选框 id = checkbox2 > Checkbox2
< / body >
< span class =code-keyword>< / html >


when i select first checkbox then automatically checked second checkbox.
how to store second checkbox id in first checkbox using javascript

解决方案

You can do it like this:

<input type="checkbox" id="Check" ></input>
<input type="checkbox" id="Check1">
</input>


In JavaScript:

function function1(){
  document.getElementById("Check1").checked = true;
}


Try this:

<!DOCTYPE html>
<html>
<head>
<script>
function myfunction()
{
    document.getElementById('checkbox2').checked = document.getElementById('checkbox1').checked
}
</script>
</head>
<body>
<input type="checkbox" id="checkbox1" onclick="myfunction();">Checkbox1
<input type="checkbox" id="checkbox2">Checkbox2
</body>
</html>


这篇关于如何使用javascript在第一个复选框中存储第二个复选框ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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