我想获取元素的 id 并想将它用于另一个子函数
function example(id) {
var me = this;
this.pro = ID
this.code = function () {
setTimeout(function () {
alert(ID)
}, 20)
}
this.validate = function () {
$('.' + id).keyup(function (e) {
var ID = this.id;
if (e.keyCode == 13) me.code()
})
}
}
身体
<input type="text" class="test" id="1" />
<input type="text" class="test1" id="2" />
<script type="text/javascript">
var test = new example('test')
var test1 = new example('test1')
test.validate()
test1.validate()
</script>