<html>
<head>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript">
/** JQUERY 通过当前标签属性名,获取属性的值 */
function attrsByJquery(obj){
var v1 = $(obj).attr("dbname");
var v2 = $(obj).attr("name");
alert(v1);
alert(v2);
}
/** JAVASCRIPT 通过当前标签属性名,获取属性的值 */
function attrsByJs(obj){
var v1 = obj.getAttribute('name');
var v2 = obj.getAttribute('dbname');
alert(v1);
alert(v2);
}
function attrsButtons(obj){
var v = obj.getAttribute('name');
var vv = $(obj).attr("myname");
alert(v);
alert(vv);
}
</script>
</head>
<body>
<p> <p style="width: 100px;
height: 30px;
float:left;
margin-left:30px;
" name="this is name feild" dbname="oracle1" onclick="attrsByJs(this)">JavaScript</p> <p style="width: 100px;
height: 30px;
float:left;
margin-left:30px;
" name="this is name feild" dbname="oracle2" onclick="attrsByJquery(this)">Juqery</p>
<input type="button" name="abcdeg" myname="this is my name" onclick="attrsButtons(this)" value="buttons">
</p>
</body>
</html>以上就是js和jquery通过this获取html标签中的属性值 的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号