trigger自动执行事件
生活随笔
收集整理的這篇文章主要介紹了
trigger自动执行事件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
html
<button>點擊文字變紅</button><p>trigger出發(fā)點擊事件</p>js
$('button').click(function(event) {$(this).next().css('color','red');});$('button').trigger('click'); //不用點擊顏色就變紅了?或者通過a來點擊b
<!DOCTYPE html> <html lang="en"><head><meta charset="utf-8"></head><style type="text/css">div{width: 200px;height: 200px;margin:20px;background-color:pink;}</style><body><div class='box1' οnclick='box1(this)'>盒子1</div><div οnclick='box2(this)'>盒子2</div></body><script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script type="text/javascript">function box1(self){console.log(self)}function box2(self){$('.box1').trigger("click")}</script> </html>?
轉(zhuǎn)載于:https://www.cnblogs.com/Model-Zachary/p/6297224.html
總結(jié)
以上是生活随笔為你收集整理的trigger自动执行事件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我写的第一本书《TypeScript 入
- 下一篇: bootstrap5