JQ根据自定义的属性绑定元素添加事件

 <body>
  
	<div id="_div" class="container" psa="aaa">sdfsdfssddiv>
	<input type="text" id="abc" value="123" psa="bbb"/>
	
  <script type="text/javascript" >
		
	$(document).ready(function() {
		$("[psa]").on("click",function(){//
			alert( 'function'== typeof $(this).html	&& $(this).html().length>0 ? $(this).html(): $(this).val());
		})
	});	
	
	script>
 body>

需要绑定元素行内自定义属性时$("[psa]"),需要使用上[] 符号去选中

你可能感兴趣的:(H5+JS+CSS)