在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 用jquery事件代理某個屬性的元素,應(yīng)該怎么寫?

用jquery事件代理某個屬性的元素,應(yīng)該怎么寫?

<label>姓 <input class="lastName" type="text" data-bind = "lastName" type = "1"></label>
this.el.on('input', '[type = "1"]' , function(){...}

用這種寫法找不到該元素,紅框處應(yīng)該怎么寫,翻遍文檔也沒找到。。

clipboard.png

回答
編輯回答
孤影

type="text" data-bind = "lastName" type = "1"

兩個type那個說了算?通過下面這個代碼我們可以發(fā)現(xiàn)attr獲取到的是text,效果觀看地址。而且你那種on(event, selector, fn)一般是用來綁在document上,也就是父級祖先級上,然后過濾觸發(fā)子節(jié)點的,文檔查看地址

$('input').on('input',function(){
  console.log($(this).attr('type'))
})
2018年9月5日 07:59
編輯回答
巫婆

'*[type=1]'

2017年3月24日 05:49
編輯回答
神曲

type = "1"不符合html規(guī)則吧,會被解析成type = "text"的,這樣寫是選不到的

document.querySelector('input.lastName')或者
 document.getElementsByClassName('lastName')[0]

不行嗎

2018年4月16日 06:32