【问题标题】:Can I make a <option> selected by clicking a link on a different page?我可以通过单击不同页面上的链接来选择 <option> 吗?
【发布时间】:2020-10-26 22:37:32
【问题描述】:

第一页有一个“请求反馈”按钮。第二页有一个带有不同 <.option> 的电子邮件表单,用于反馈、评论和问题。

有没有办法让它在您单击“请求反馈”按钮时将您重定向到第二页并自动将 <.option> 设置为反馈?

<select name="subject" id="subject">
  <option value="feedback">Feedback</option>
  <option value="comment">Comment</option>
  <option value="question">Questions</option>
</select>

【问题讨论】:

标签: html css contact-form


【解决方案1】:

第 1 页:

<a href="page2.html?q=feedback"> Request Feedback</a>

第 2 页:

const q = urlParams.get('q')
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

document.getElementById("subject").value = q;
<select name="subject" id="subject">
                                <option value="feedback">Feedback</option>
                                <option value="comment">Comment</option>
                                <option value="question">Questions</option>
</select>

【讨论】:

    猜你喜欢
    • 2018-08-11
    • 2023-03-04
    • 2011-10-26
    • 2018-06-24
    • 2017-12-13
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 2018-04-06
    相关资源
    最近更新 更多