开发者

Passing jQuery Selectors to a function Server side

I want to pass jQuery selectors to a Javascript function Server side.

Here is my Javascript function :

     function DisableOperations(Selector) {
        alert(Selector);

        $(Selector).parent().find('input').attr('disabled', true);
    }

And it is my server side code :

string Selectors = "a:contains('test1') a:contains('test2')";
ScriptManager.RegisterStartupScript(this, GetType(), "DisplayMessage", string.Format("DisableOperations('{0}');", Selectors), true)

This code doesn't work (Javascript function doesn't call) because variable selectors contains this (').

And when I write

string Selectors = "a:开发者_开发知识库contains(test1) a:contains(test2)";

jQuery selector doesn't because argument in 'contains' function in selector should be between ' and '.

What is the solution ?


Have you tried var sel = eval(Selector); ?
first just try escaping your single quotes. "a:contains(\'test1\') a:contains(\'test2\')"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜