简体   繁体   English

JavaScript:参数传递不适用于所有浏览器

[英]JavaScript: Argument passing doesn't work on all browsers

I'm trying to pass an argument to a function, which works fine on Chrome but not on all versions of Firefox. 我试图将一个参数传递给一个函数,该函数在Chrome上运行正常但在所有版本的Firefox上都不行。 Here's the code : 这是代码:

  $('input').focus(function()
  {
     alert(this.width);
   });

this.width appears to be undefined on some versions of FF. 在某些版本的FF上,this.width似乎未定义。

Please help me. 请帮我。

From your description, it seems the problem has nothing to do with passing an argument to a function, it's just that this.width is undefined in some browsers? 从你的描述来看,似乎问题与将参数传递给函数无关,只是在某些浏览器中未定义this.width I couldn't find documentation for width as a property of an input element, so it doesn't surprise me that it doesn't work consistently. 我找不到width作为输入元素属性的文档,所以它并不让我感到惊讶,它不能始终如一地工作。

Have you tried this.offsetWidth ? 你试过this.offsetWidth Or this.style.width ? 还是this.style.width

Or given that you seem to be using jQuery you might also look at $(this).width() . 或者考虑到你似乎在使用jQuery,你也可以看看$(this).width()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM