jquery attribute indexOf
When I am getting at an attribute onclick
of custom(Reporting Services) checkbox it gives me correct result. However when I am trying to use indexOf
on that result it says "Object doesn't support this property or method", i.e. this is fine, gives me a long string
$('input[id*=CustomCheckBox]').click(function()
{
alert( $(this)开发者_开发问答.attr("onclick") );
});
But this gives an error(object doesn't support this property or method):
$('input[id*=CustomCheckBox]').click(function()
{
if ($(this).attr("onclick").indexOf("SomeString") > -1 )
{
//do some processing here
}
}
What would I need to modify so that indexOf
is working properly?
I agree with Nick Carver above, but if you still need to do it, you simply need to cast the attribute as a string before you try to use indexOf
. I tested it quickly in Safari and it seemed to work as expected.
if (String($(this).attr("onclick")).indexOf("SomeString") > -1 )
{
//do some processing here
}
You can use the onclick
event itself, not the most efficient, but if it's your only option... You'd do it like this:
$('input[id*=CustomCheckBox]').click(function() {
if (this.onclick && this.onclick.toString().indexOf("SomeString") > -1 ) {
alert('found!')
} else {
alert('not found :(');
}
});
You can try a demo here
精彩评论