onclick获取同级元素属性

文章描述:

js中onclick获取同级元素属性信息

jquery-2.1.4.min.js

<div class="container">
	<select name="role_id">
    	<option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>
	<div id="replySubmit"  onclick="replySubmit(this,3)" >确定</div>
</div>
function replySubmit (doc,id) {
	console.log(doc);
	console.log(id);
	var text = $(doc).text();
	console.log(text);
	var val = $(doc).prev('select').val();
	console.log(val);
	var name = $(doc).prev("select").attr('name')
	console.log(name);
}

 

发布时间:2023/04/04

发表评论