我想从onclick事件传递属性和它们的值到JavaScript函数,但它们返回undefined。发送onclick控制到javascript函数
<script type="text/javascript">
function addParameters(control) {
alert(control._userid);
alert(control._flag);
}
<button text="Button" ID="btn1" _userid="datatest" _flag="datafromdatabaase" title="Add this to the list" onclick="addParameters(this);"> Button</button>
[使用Javascript/jQuery从HTML元素获取所有属性]的可能重复(http://stackoverflow.com/questions/2048720/get-all-attributes-from-a-html-element-with-javascript- jQuery) – Lucio
你不应该使用你自己的任何属性来制作HTML中不存在的属性。改为使用自定义数据属性。 – CBroe