Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用按钮单击事件javascript高亮显示多条记录_Javascript_Jquery - Fatal编程技术网

使用按钮单击事件javascript高亮显示多条记录

使用按钮单击事件javascript高亮显示多条记录,javascript,jquery,Javascript,Jquery,我在JSFIDLE上找到了以下代码。此代码一次仅高亮显示一行。但我需要一次突出显示多行,当点击按钮时,它们应该保持不变。有人能帮我吗 Javascript 移除循环并执行切换类 函数highlightctrl{ var parent=ctrl.parentNode.parentNode; ifparent.classList==新的反向更改{ parent.classList.removebackChange; } 否则{ parent.classList.addbackChange; } }

我在JSFIDLE上找到了以下代码。此代码一次仅高亮显示一行。但我需要一次突出显示多行,当点击按钮时,它们应该保持不变。有人能帮我吗

Javascript


移除循环并执行切换类

函数highlightctrl{ var parent=ctrl.parentNode.parentNode; ifparent.classList==新的反向更改{ parent.classList.removebackChange; } 否则{ parent.classList.addbackChange; } } 1.换钱{ 背景:红色; } 选择 名称 地方 行动 名称 地方 选择 名称 地方 选择 名称 地方 选择 名称 地方 选择
function highlight(ctrl){
   var elements=document.getElementsByTagName('tr');
    for(var i=0;i<elements.length;i++)
        elements[i].classList.remove('backChange');
   var parent=ctrl.parentNode.parentNode;
   parent.classList.add("backChange");
}

document.write("<table id=appTable border=1 style=margin-top:10px; margin-left:10px;>")
        document.write("<tr><th>Select</th><th>Name</th><th>Location</th><th>Action</th></tr>");
for (row=1; row<5; row++) {
                     document.write("<tr class='New'>")
                     for (col=1; col<=4; col++) {
                            if(col==1)
                {                       document.write("<td><input type='checkbox' id='mapCheck' name='myTextEditBox' /></td>")
                }

                            if(col==2)
                                 document.write("<td width='140'>Name</td>")
                            if(col==3)
                                 document.write("<td width='200'>Location</td>")
                if(col==4)
                 document.write("<td><button type='button' onclick='highlight(this)'>select</button></td>")
                        }
                document.write("</tr>")
                }
        document.write("</table>")
.backChange{
    background:red;
}