1

I'm making a custom sorting tool for my custom gridview.

I use jQuery ui $.autocomplete() to find DISTINCT VALUEs from a COLUMN in a TABLE.

I then add the selected values to a jquery ui $.selectable().

I usually use the id attribute to store distinct type values like this (such as TABLE PRIMARYies), so my problem comes in when I try to store these values where they probably will not be compliant with HTML id standards or readable by jQuery.

How can I create a function to escape and de-escape any text from a database into HTML id readable by jQuery and back again?

4

2 回答 2

2

要进行编码/解码,您可以使用此答案中描述的功能

要进行 jquery 查找,您可以使用$('[id="' + escapedId + '"]');. 这不是最有效的,但它可以保证您的任何特殊字符都不会被误认为是选择器的一部分。

于 2013-04-19T15:57:22.597 回答
1

data-您可以根据 HTML5 规范(也向后兼容早期版本的 HTML)在任何带有前缀的 HTML 对象上存储自定义属性。这些可以在选择器查询中使用(与在查询中使用任何属性的方式相同)或者可以使用 jQuery 的.data(). 对于可以在自定义属性(如引号)中的字符仍有一些限制,但它比 id 值限制更少。

于 2013-04-19T16:22:07.247 回答