jquery函数参数传递

abc_lala 2017-05-11 12:51:59
$(document).ready(function() {
$(":text").focus(
check($(this))
)
function check($this){
$this.css("display","none");
alert("hello");
}
});
后面的alert只是想测试,结果打开页面,直接输出个hello,还没等我触发focus事件。另外当焦点在text框中时,也没有使框消失
SO why?
...全文
204 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
幽兔 2017-05-11
  • 打赏
  • 举报
回复
引用 2 楼 abc_lala 的回复:
[quote=引用 1 楼 ghoslation 的回复:] $(":text").focus( check($(this)) ) 这个语句执行顺序是 1。选取所有text对象 2。执行check函数 3。将check函数的结果邦定在focus事件上 所以这一语句执行之后, 事实上check函数已经被执行。 解法: $(document).ready(function() { $(":text").focus(function (){ $this = $(this); $this.css("display","none"); alert("hello"); }); });
我想中间包裹一个函数,因为我有几个地方代码几乎一致,只是传递的this对象不同。所以说我将focus里面的function 包裹的代码换成函数即可是吧?[/quote] YES
yanxinlian 2017-05-11
  • 打赏
  • 举报
回复
引用 3 楼 yanxinlian 的回复:

$(document).ready(function() {
   $(":text").focus(function(e) {
       check($(this)); 
    });
  function check(obj){
      obj.css("display","none");
      alert("hello");
  }
});
focus事件 $(select).focus(function(){ //do something }) 获得焦点 $(select).focus()
Msxindl_Com 2017-05-11
  • 打赏
  • 举报
回复

$(":text").focus(function(){
	check($(this));
});
天际的海浪 2017-05-11
  • 打赏
  • 举报
回复
$(":text").focus(function(){ check($(this)) })
yanxinlian 2017-05-11
  • 打赏
  • 举报
回复

$(document).ready(function() {
   $(":text").focus(function(e) {
       check($(this)); 
    });
  function check(obj){
      obj.css("display","none");
      alert("hello");
  }
});
abc_lala 2017-05-11
  • 打赏
  • 举报
回复
引用 1 楼 ghoslation 的回复:
$(":text").focus( check($(this)) ) 这个语句执行顺序是 1。选取所有text对象 2。执行check函数 3。将check函数的结果邦定在focus事件上 所以这一语句执行之后, 事实上check函数已经被执行。 解法: $(document).ready(function() { $(":text").focus(function (){ $this = $(this); $this.css("display","none"); alert("hello"); }); });
我想中间包裹一个函数,因为我有几个地方代码几乎一致,只是传递的this对象不同。所以说我将focus里面的function 包裹的代码换成函数即可是吧?
幽兔 2017-05-11
  • 打赏
  • 举报
回复
$(":text").focus( check($(this)) ) 这个语句执行顺序是 1。选取所有text对象 2。执行check函数 3。将check函数的结果邦定在focus事件上 所以这一语句执行之后, 事实上check函数已经被执行。 解法: $(document).ready(function() { $(":text").focus(function (){ $this = $(this); $this.css("display","none"); alert("hello"); }); });

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧