开发者

Passing jQuery Selectors to a function Server side

开发者 https://www.devze.com 2023-03-17 11:10 出处:网络
I want to pass jQuery selectors to a Javascript function Server side. Here is my Javascript function :

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

精彩评论

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