用于将html实体转换为从url传递的任何javascript构建函数
我有价值用于将html实体转换为从url传递的任何javascript构建函数,javascript,replace,html-entities,urldecode,Javascript,Replace,Html Entities,Urldecode,我有价值 abc}efg 我需要它从URL传递 in HTML } = } in URL } = %7D 如何转换}到%7D?函数名为encodeURIComponent,幸运的是它是一个内置函数。您可以免费使用它: alert( encodeURIComponent("}") ) //-- alert box will show "%7D" 结合 jQuery的函数基本上是一个围绕(普通DOM)的薄函数包装器,因此,如果您
abc}efg
我需要它从URL传递
in HTML } = }
in URL } = %7D
如何转换
}
到%7D
?函数名为encodeURIComponent,幸运的是它是一个内置函数。您可以免费使用它:
alert( encodeURIComponent("}") ) //-- alert box will show "%7D"
结合
jQuery的函数基本上是一个围绕(普通DOM)的薄函数包装器,因此,如果您不使用jQuery,链接问题仍然适用。听起来您想:
function browerURLtoEntity( code ) {
var crypt = {};
crypt.URI = code;
crypt.ascii = decodeURLComponent(crypt.URI);
crypt.entity = Encoder.htmlEncode(crypt.ascii);
return crypt;
}
// crypt.entity will be the piece that you want.
当然-但这并不能解决HTML实体的问题。您需要首先处理“encodeURIComponent(}”)”