0

我不太擅长 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

它变成了=to%3D&to %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';
    }
  });
})();

4

0 回答 0