700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > html点击子元素 js获取被点击的元素以及子元素

html点击子元素 js获取被点击的元素以及子元素

时间:2019-01-21 22:30:04

相关推荐

html点击子元素 js获取被点击的元素以及子元素

js获取被点击元素:

获取被点击的元素

body {margin: 0px;}

#container {width: 700px;height: 300px;padding:5px;background-color: #edfdef;}

function getClickEle(ele){

console.log($(ele).val()); //方法一:通过jquery对象,获取被点击的元素

console.log(ele.tagName); //方法二:通过传入js 元素对象,获取

//$(document).click(function(e){console.log(e.target.value)});

}

function getClildVal(ele){

console.log($(ele).find("#girl_1")[0].tagName); //方法五:获取被点击的元素的子元素转jquery对象,再获取子元素

console.log($($(ele).find("#girl_1")[0]).attr("id")); //方法六:获取被点击的元素的子元素

}

姓名:

电话:

手机:

email:

QQ:

下面有个可爱的女孩:

$("#phone").click(function(){

console.log($(this).val()); //方法三:获取被点击的元素,转jquery对象

console.log(this.tagName); //方法四:获取被点击的元素

});

参见以上代码

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。