Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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 从JS节点中的模板操纵按钮属性_Javascript_Jquery_Node.js_Dom - Fatal编程技术网

Javascript 从JS节点中的模板操纵按钮属性

Javascript 从JS节点中的模板操纵按钮属性,javascript,jquery,node.js,dom,Javascript,Jquery,Node.js,Dom,我有一个HTML模板,由一个包含三个按钮的DIV组成 <template ID="template3buttons"> <div ID="container3buttons" class="boxes"> <div ID= "sunShadeUp" class="boxes"> <input type="button" id="SunshadeButtonUp"

我有一个HTML模板,由一个包含三个按钮的DIV组成

<template ID="template3buttons">
    <div ID="container3buttons" class="boxes">
        <div ID= "sunShadeUp" class="boxes">
            <input type="button" 
               id="SunshadeButtonUp" 
               class="SunshadeSmallButton"
               onclick="GenericAction('ENO_ShutterStop($all)', 'all')" 
               value=""/>
        </div>
        <div ID= "sunShadeStop" class="boxes">
            <input type="button" 
               id="SunshadeButtonStop"
               class="SunshadeSmallButton"
               onclick="GenericAction('ENO_ShutterStop($all)', 'all')" 
               value=""/>
        </div>
        <div ID= "sunShadeDown" class="boxes">
            <input type="button" 
               id="SunshadeButtonDown"
               class="SunshadeSmallButton"
               onclick="GenericAction('ENO_ShutterStop($all)', 'all')" 
               value=""/>
        </div>
    </div>
</template>

现在,我需要根据插入点操作模板每个副本的“onclick”标记的内容。我知道
getElementById()
不适用于DOM节点。有哪些替代方案?

如果使用jQuery,可以执行以下操作:

$("[id*=sunShade]").children().click(function() {
  alert( "Handler for .click() called." );
});

亲爱的lkmac,谢谢你的帮助。如果我使用“$”(“#box11”).children().click(函数(){alert(“Handler for.click()called.”);}),您的建议就可以了;其中,框11是包含模板副本的20个框之一。但是,我想知道是否有更优雅的方法从DIV的Id中提取数字“11”并以编程方式使用它,这样我就不必维护20个连续的按钮。很抱歉,最初没有得到您的答案。我更新了我的答案,现在试试。
$("[id*=sunShade]").children().click(function() {
  alert( "Handler for .click() called." );
});