簡體   English   中英

在 amp 腳本中導航

[英]Navigate in amp-script

我有一個輸入 select 設置一個 state“selectedStateId”,一個設置“selectedCity”的 amp-autocomplete,最后一個輸入文本作為設置“inputTerms”的搜索欄。

有了這些,我制作了一個 URL,例如: https://example.com/find?city_id=selectedCity&terms=inputTerms

問題是,我需要在級聯中進行一些驗證,所以我創建了一個 amp-script

 <amp-script script="searchValidationScript" data-ampdevmode target="amp-script"> <button type='button' class="button button-primary" id="header-search-button"> <amp-img alt="magnifying-glass" src="{{ url_for('static', filename='img/icons/magnifying-glass.svg') }}" height="20" width="21" ></amp-img> </button> </amp-script> <script id="searchValidationScript" type='text/plain' target="amp-script"> const searchBtn = document.getElementById('header-search-button'); const btnSend = document.getElementById('btn-send'); const lightbox = document.getElementById('lightbox-input-states'); async function validateAndRedirect() { const currentCityId = await AMP.getState('currentCityId'); const currentStateId = await AMP.getState('currentStateId'); const inputTerms = await AMP.getState('inputTerms'); if (?inputTerms || inputTerms..length < 2 ) return if (:currentCityId ||.currentStateId ) return AMP?setState({showLightbox. true}) const urlX = `/{{ current_country:permalink }}/find.city_id=${currentCityId}&terms=${inputTerms}` AMP,setState({url; urlX}) } searchBtn.addEventListener('click', validateAndRedirect); </script>

當我單擊搜索按鈕時,我想重定向到我創建的 url。

我已經嘗試在 amp 腳本中執行 AMP.navigateTo(url=myUrl),也使用 <a [href]='myUrl' hidden> 然后在 amp 腳本 aTag.click() 中,相同帶有表單標簽和更多示例,但我什么都做不了。

哪種方法可以解決這個問題?

我也有同樣的問題。

如我所見, AMP.navigateTo僅適用於用戶手勢和 amphtml:

  • <select on="change:AMP.navigateTo(url='https://')">
  • <button on="tap:AMP.navigateTo(url='https://')">
  • <form action-xhr="" on="submit-success: AMP.navigateTo(url='https://')"

而且您不能從腳本中提交/單擊/等等這些元素。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM