2011-09-26 83 views
1

我有一個jQuery插件,它就像大多數的插件以這種格式如何將jQuery插件綁定到ASP.NET代碼中的元素?

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

現在我有其中運行時在ASP.NET中的代碼確定後面的字符串的情況下,它的每一個元素不同。這可以在服務器控件的OnItemDataBound中完成。頁面中可能有數十個。

如何在後面的代碼中綁定jQuery插件?

增加:

每個 'someelement' 可以有不同的ID。

回答

1

我建議您使用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') 
    }); 
}); 
+0

我需要支持IE 7和8 –

+0

@Tony_Henrich - 這會也在那裏工作。 HTML5只是將其標準化。 –

+0

jQuery對此很好的支持。 –

相關問題