我有一个用perl编码的字符串,使用
uri_escape ($string);然后,我将其传递给Javascript,并通过
fileName = decodeURIComponent ($somevariable);然后,我对变量发出警报,字符串显示正确(在本例中)
his33a;Cell-Line_Fly-biotin-tagged-H33;Tissue_embryo-derived-cell-line;Developmental-Stage_late-embryonic-stage;Compound_80-600-mM;extract_soluble-fraction;sampling_time_point_1-–-2-hours;DNA-tiling-array;Rep-2;Dmel_r54;modENCODE_2523;GSM333854.wiggle但是,在HTML中,它显示为
his33a%3BCell-Line_Fly-biotin-tagged-H33%3BTissue_embryo-derived-cell-line%3BDevelopmental-Stage_late-embryonic-stage%3BCompound_80-600-mM%3Bextract_soluble-fraction%3Bsampling_time_point_1-%E2%80%93-2-hours%3BDNA-tiling-array%3BRep-2%3BDmel_r54%3BmodENCODE_2523%3BGSM333854.wiggle发布于 2011-08-19 09:41:23
Perl/URI::Escape的uri_escape和JavasScript的encodeURIComponent不做同样的事情。为了保证兼容性,请使用CPAN的JavaScript模块:
use 5.014;
use warnings;
use JavaScript;
use URI::Escape;
my $rt = JavaScript->create_runtime();
my $cx = $rt->create_context();
my $string = 'his33a;Cell-Line_Fly-biotin-tagged-H33;Tissue_embryo-derived-cell-line;Developmental-Stage_late-embryonic-stage;Compound_80-600-mM;extract_soluble-fraction;sampling_time_point_1-–-2-hours;DNA-tiling-array;Rep-2;Dmel_r54;modENCODE_2523;GSM333854.wiggle';
# Perl:
say uri_escape($string);
# his33a%3BCell-Line_Fly-biotin-tagged-H33%3BTissue_embryo-derived-cell-line%3BDevelopmental-Stage_late-embryonic-stage%3BCompound_80-600-mM%3Bextract_soluble-fraction%3Bsampling_time_point_1-%E2%80%93-2-hours%3BDNA-tiling-array%3BRep-2%3BDmel_r54%3BmodENCODE_2523%3BGSM333854.wiggle
# JavaScript:
$cx->eval(qq|
function escape_uri(string) { return encodeURIComponent(string) }
|);
say $cx->call('escape_uri', $string);
# his33a%3BCell-Line_Fly-biotin-tagged-H33%3BTissue_embryo-derived-cell-line%3BDevelopmental-Stage_late-embryonic-stage%3BCompound_80-600-mM%3Bextract_soluble-fraction%3Bsampling_time_point_1-%C3%A2%C2%80%C2%93-2-hours%3BDNA-tiling-array%3BRep-2%3BDmel_r54%3BmodENCODE_2523%3BGSM333854.wigglehttps://stackoverflow.com/questions/7114430
复制相似问题