如何将jQuery插件绑定到ASP中的元素.NET代码



我有一个jQuery插件,它可以像大多数这种格式的插件一样工作

$(somelement).SomePlugin(some options); one of the options is a string.

现在我有一个情况,其中字符串是在ASP运行时确定的。NET中的代码,每个元素都是不同的。这可以在服务器控件的OnItemDataBound中完成。这一页可能有几十个。

如何在代码后面绑定jQuery插件?

添加:

每个'someelement'可以有一个不同的id。

我建议你使用HTML5的data属性。例如:

<li data-thestringoption="some String"></li>
<li data-thestringoption="some other String"></li>

然后,当你调用你的插件,你可以使用data属性:

$('li').each(function() {
    $(this).SomePlugin({
        someOption: 32,
        theStringOption: $(this).data('thestringoption')
   });
});

最新更新