1.直接传递给定参数如:
onclick="selectAttr('1'); onclick="selectAttr('a');
2.传递某属性值
<input type="text" id="nameId" name="typeName"> onclick="selectAttr(typeName.value); onclick="selectAttr(nameId.value);
3.传递this对象
onclick="selectAttr(this);
通过this对象获取对应选项值:this.value or this.name;
如果是自定义属性可以通过以下方式获取:
document方式获取:
var divs=document.getElementById("typeName1"); var x=divs.getAttribute("code");
code为自定义属性。
jqery方式获取:
$("#typeName").attr("value"); var typeName=$("#sel").find("option:selected").attr("code");
以上就是HTML通过事件传递参数到js详解及实例的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于HTML通过事件传递参数到js详解及实例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did100737