页面某一个元素跟随输入框输入内容动态变化
要考慮多種事件? 如keyup ,blur
?
事件綁定方法:
多個事件綁定同一個函數
$(document).ready(function(){
? $("input").on("keyup blur",function(){
? ? //代碼
? });
});
多個事件綁定不同函數
$(document).ready(function(){
? $("p").on({
? ? mouseover:function(){$("body").css("background-color","lightgray");}, ?
? ? mouseout:function(){$("body").css("background-color","lightblue");},?
? ? click:function(){$("body").css("background-color","yellow");} ?
? });
});
綁定自定義事件
$(document).ready(function(){
? $("p").on("myOwnEvent", function(event, showName){
? ? $(this).text(showName + "! What a beautiful name!").show();
? });
? $("button").click(function(){
? ? $("p").trigger("myOwnEvent",["Anja"]);
? });
});
傳遞數據到函數
function handlerName(event) {
? alert(event.data.msg);
}
$(document).ready(function(){
? $("p").on("click", {msg: "You just clicked me!"}, handlerName)
});
適用于未創建的元素(事件委托)
$(document).ready(function(){
? $("div").on("click","p",function(){
? ? $(this).slideToggle();
? });
? $("button").click(function(){
? ? $("<p>This is a new paragraph.</p>").insertAfter("button");
? });
});
轉載于:https://www.cnblogs.com/lcddjm/p/6542889.html
總結
以上是生活随笔為你收集整理的页面某一个元素跟随输入框输入内容动态变化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tomcat无法访问中文路径的解决办法
- 下一篇: Exynos4412裸机开发 —— 看门