English 中文(简体)
分类指数 其中
原标题:jquery attribute indexOf

当我拿到海关(报告服务)检查箱的属性<编码>onclick时,就会给我带来正确的结果。 然而,当我试图使用<代码>indexOf时,它就这样说,“目标并不支持这种财产或方法”,即是罚款,使我有很长的路要走。

$( input[id*=CustomCheckBox] ).click(function()
{
      alert( $(this).attr("onclick") );


});

但是,这会造成错误(目标并不支持这种财产或方法):

$( input[id*=CustomCheckBox] ).click(function()
{
     if ($(this).attr("onclick").indexOf("SomeString") > -1 )
     {
          //do some processing here

     }
}

我们需要做些什么来修改<代码>indexOf?

最佳回答

我同意上文的尼克·卡韦,但如果你仍然需要这样做,你就只需在你试图使用之前把属性作为指示。 我很快在Safari测试了这一试验,似乎像预期的那样工作。

if (String($(this).attr("onclick")).indexOf("SomeString") > -1 )
 {
      //do some processing here

 }
问题回答

您可使用<代码>onclickevent。 它本身不是效率最高,而是是唯一的选择...... 阁下:

$( input[id*=CustomCheckBox] ).click(function() {
  if (this.onclick && this.onclick.toString().indexOf("SomeString") > -1 ) {
    alert( found! )
  } else {
    alert( not found :( );
  }
});

页: 1





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签