To achieve this functionality in JavaScript, you can modify your chb
function to check the checkbox inside the clicked
. Here’s how you can do it: مقالات ذات صلة
htmlhtml>
<html>
<head>
<title>Checkbox Selectiontitle>
head>
<body>
<table>
<tr>
<td id="1" onclick="chb('1')"><input type="checkbox" />title 1td>
tr>
<tr>
<td id="2" onclick="chb('2')"><input type="checkbox" />title 2td>
tr>
table>
<script>
function chb(tdId) {
var td = document.getElementById(tdId);
var checkbox = td.querySelector('input[type="checkbox"]');
checkbox.checked = !checkbox.checked;
}
script>
body>
html>
In this example, the chb
function takes the id
of the clicked
. It then finds the checkbox inside that
using querySelector
and toggles its checked state. This way, when you click on a
, the corresponding checkbox will be checked or unchecked.المزيد من المعلومات
لتحقيق هذا الوظيفة في JavaScript، يمكنك تعديل وظيفة chb
لتحديد خانة الاختيار داخل العنصر
المحدد. فيما يلي كيفية القيام بذلك:
htmlhtml>
<html>
<head>
<title>Checkbox Selectiontitle>
head>
<body>
<table>
<tr>
<td id="1" onclick="chb('1')"><input type="checkbox" />العنوان 1td>
tr>
<tr>
<td id="2" onclick="chb('2')"><input type="checkbox" />العنوان 2td>
tr>
table>
<script>
function chb(tdId) {
var td = document.getElementById(tdId);
var checkbox = td.querySelector('input[type="checkbox"]');
checkbox.checked = !checkbox.checked;
}
script>
body>
html>
في هذا المثال، تأخذ وظيفة chb
الهوية id
للعنصر
الذي تم النقر عليه. ثم تجد خانة الاختيار داخل ذلك
باستخدام querySelector
وتقوم بتبديل حالتها بين محددة وغير محددة. بهذه الطريقة، عند النقر على
، ستتم مراجعة خانة الاختيار المقابلة.