如何通过url hash将值传递给多个选择下拉列表

时间:2016-10-13 14:48:29

标签: javascript jquery url hash

我正在尝试通过url hash传递三个不同的select下拉列表的值。因此,如果我输入'http://mywebsite.com/page#value1AppleThursday',如果将相同的值传递到各自的选择下拉列表。这可能吗?

谢谢!

这是我的HTML:

<ul class="filters">
  <li>
      <select id="type-select" class="input-select">
          <option value="value1">Option 1</option>
          <option value="value2">Option 2</option>
          <option value="value3">Option 3</option>
      </select>
  </li>
  <li>
      <select id="duration-select" class="input-select">
          <option value="apple">Apple</option>
          <option value="orange">Orange</option>
          <option value="grape">Grape</option>
          <option value="banana">Banana/option>
      </select>
  </li>
  <li>
      <select id="sc-select" class="input-select">
        <option value="monday">Monday</option>
        <option value="tuesday">Tuesday</option>
        <option value="wednesday">Wednesday</option>
        <option value="thursday">Thursday</option>
        <option value="friday">Friday</option>
      </select>
  </li>
</ul>

1 个答案:

答案 0 :(得分:0)

您可以通过大写每个参数的第一个字母('http://mywebsite.com/page#Value1AppleThursday)来实现:

public IEnumerable<Object> GetObjectsFromRequest(FindObjectRequest request)
{
    foreach(var kvp in request.SearchFilters)
    {
        var key = kvp.Key;
        var value = kvp.Value;

        yield return metaDataRepository.MetaDataPairs
            .Where(md => md.Key.ToLower() == key && md.Value.ToLower().Contains(value))
            .Select(md => md.ObjectChild.Object)
    }
}

或者您可以使用分隔符“|”分隔三个参数('http://mywebsite.com/page#value1|Apple|Thursday)或您喜欢的任何其他符号:

Object