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 writestring 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\')"
精彩评论