获取标签的属性,比如input
1、已知id,name等属性,通过选择器实现
(摘自https://www.cnblogs.com/royfans/p/7821276.html)
$(" #test “).val()
$(” input[ name=‘test’ ] “).val()
$(” input[ type=‘text’ ] “).val()
$(” input[ type=‘text’ ]").attr(“value”)
2、通过this实现:
(对该博主内容的一个补充)
<input type="text" id="123" onblur="func(this)"/>
function func(e) {
const user_name = e.value
const user_id = e.id
const greet = (name,id) => {
alert(`Hello! ${name}, your ID is ${id}`)
}
greet(user_name,user_id)
}