获取html结点的属性

获取标签的属性,比如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)
    }
原创文章 3 获赞 3 访问量 382

猜你喜欢

转载自blog.csdn.net/qq_36603596/article/details/103112003