-1

I'm not familiar with JS, so please help me here

I've used to call element like this before:

$(.ddlPage).change();

Now I would like to replace 'ddlPage' with a string variable. How can I call it with variable?

$(.elemID).change(); (is obviously wrong)
4

3 に答える 3

1

First of all, pass a string parameter to jQuery. In your case (if it is not a typo) you pass some variables in there, which works in some cases, but not in general.

Then just build the selector you need, so, e.g.:

var elemId = 'myId'; 
$( '#' + elemID ).change();

Or to search for a class:

var elemClass = 'myClass'; 
$( '.' + elemClass ).change();

etc. Just built up a string containing the selector you need and pass it on to jQuery.

于 2012-12-04T15:52:50.990 に答える
0

Use the id selector

$("#ddlPage").change()
于 2012-12-04T15:51:44.320 に答える
0

I think what you really need is a basic understanding of jQuery selectors.

Review the material here: http://www.w3schools.com/jquery/jquery_selectors.asp

于 2012-12-04T15:54:12.933 に答える