你的子页面是一个iframe吗?如果是这样,你可以往iframe的url传入一个参数如btnid:
http://your-iframe-url.com/page/?btnid,子页面通过location.search获取到查询字符串“?btnid”,你自己去掉问号,就可以获取到父页面的btnid了。
我还是写个简单的例子吧:
父页面的js:
$(".btn").click(function(){$("#child-frame").src="http://your-iframe-url.com/page/?"+this.id
})
子页面的js:
var id = location.search.substr(1)<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no">
<title>Title</title>
</head>
<body>
<div id="container">
<div id="id_1">textContent_1</div>
<div id="id_2">textContent_2</div>
<div id="id_3">textContent_3</div>
<div id="id_4">textContent_4</div>
<div id="id_5">textContent_5</div>
<div id="id_6">textContent_6</div>
<div id="id_7">textContent_7</div>
<div id="id_8">textContent_8</div>
<div id="id_9">textContent_9</div>
<div id="id_10">textContent_10</div>
<div id="no_1">textContent_no_event_call</div>
<div id="no_2">textContent_no_event_call</div>
<div id="no_3">textContent_no_event_call</div>
<div id="no_4">textContent_no_event_call</div>
<div id="no_5">textContent_no_event_call</div>
</div>
<script type="text/javascript">
//采用代理方式处理
var divs = document.querySelectorAll("div[id^='id_']")
var ids = Array.prototype.slice.call(divs).map(function (div) {
return div.id
})
document.querySelector('#container').addEventListener('click', function (e) {
if (ids.indexOf(e.target.id) > -1) {
alert(e.target.textContent)
}
}, false)
</script>
</body>
</html>
$(".class名称").click(function(){alert($(this).attr('id'))
})
或者
$("a").on('click',fuction(){
var a_id = this.id
alert(a_id)
})