防止URL字符串在JavaScript中编码

时间:2012-08-19 20:39:13

标签: javascript

我不擅长JavaScript并且有一些为我编写的代码:

if (args[2].LocationCacheTypeID == 1) {
  locationInput.name = 'Cities';

我想将LinkID=27201&添加到代码中,如下所示:

if (args[2].LocationCacheTypeID == 1) {
  locationInput.name = 'LinkID=272081&Cities';

唯一的问题是,当我添加它并将其转换为URL字符串时,结果为:

?LinkID%3D272081%26Cities=Poquoson

它将=变为%3D,将&变为%26

我该如何解决这个问题?

完整的原始剧本是:

<script type='text/javascript'>
(function() {
  var dataSource = new YAHOO.util.ScriptNodeDataSource('http://api.idx.diversesolutions.com/API/Locations/33266/81?');
  var ac = new YAHOO.widget.AutoComplete('vrcsf_location', 'vrcsf_location_ac', dataSource);

  dataSource.responseSchema = {
    resultsList: '',
    fields: ['LocationName','LocationCacheTypeID','TotalCount']
  };

  ac.animVert = false;
  ac.queryMatchContains = true;
  ac.queryQuestionMark = false;
  ac.useShadow = true;
  ac.queryDelay = .1;
  ac.typeAhead = false;
  ac.allowBrowserAutocomplete = false;
  ac.alwaysShowContainer = false;
  ac.resultTypeList = false;
  ac.maxResultsDisplayed = 5;
  ac.resultTypeList = false;

  ac.generateRequest = function(query) {
    return 'partialName=' + query + '&maxAreasToReturn=5';
  };

  ac.formatResult = function(resultData, query, resultMatch) {
    var type;

    if (resultData.LocationCacheTypeID == 1) {
      type = 'City';
    } else if (resultData.LocationCacheTypeID == 2) {
      type = 'Community';
    } else if (resultData.LocationCacheTypeID == 3) {
      type = 'Tract';
    } else if (resultData.LocationCacheTypeID == 4) {
      type = 'Zip';
    } else if (resultData.LocationCacheTypeID == 5) {
      type = 'County';
    }
    return (resultMatch + ' (' +  type + ')');
  };

  ac.itemSelectEvent.subscribe(function(e, args) {
    var locationInput = YAHOO.util.Dom.get('vrcsf_location');

    if (args[2].LocationCacheTypeID == 1) {
      locationInput.name = 'Cities';
    } else if (args[2].LocationCacheTypeID == 2) {
      locationInput.name = 'Communities';
    } else if (args[2].LocationCacheTypeID == 3) {
      locationInput.name = 'Tracts';
    } else if (args[2].LocationCacheTypeID == 4) {
      locationInput.name = 'ZipCodes';
    } else if (args[2].LocationCacheTypeID == 5) {
      locationInput.name = 'Counties';
    }
  });
})();

0 个答案:

没有答案