简体   繁体   English

按一页上的按钮高亮显示新页面上的按钮

[英]pressing button on one page highlights button on new page

So i have two pages and one has a list of buttons (page a) and the other page only has one(page b). 所以我有两个页面,一个页面有一个按钮列表(页面a),另一页面只有一个页面(页面b)。 Im looking for a way that if you press the button on page b it will take me to page a with the second button with .focus() already targeting it. 我正在寻找一种方法,如果您按页面b上的按钮,将带我进入第二个带有.focus()目标按钮的页面。 here are some links for the code i have written this is for page a http://jsfiddle.net/posgarou/S96zw/ 这是我编写的代码的一些链接,该链接用于页面http://jsfiddle.net/posgarou/S96zw/

HTML page a HTML页面

<button type="button" id="button0" onClick="reply_click(this.id)">button0</button><p></p>
<button type"button" id="button1" onClick="reply_click(this.id)">button1</button><p></p>
<button type"button" id="button2" onClick="reply_click(this.id)">button2</button><p></p>
<textarea id="myArea"></textarea>
<button type"button" id="button0" onClick="reply_click(this.id)">focus on button 0</button><p></p>

JAVASCRIPT (just used the same for both pages) JAVASCRIPT(两个页面使用的相同)

function reply_click(clicked_id){
  var id= clicked_id;
  var myTextArea = document.getElementById('myArea');
  myTextArea.innerHTML += id;
  document.getElementById(id).focus(); 
};

and this is for page b http://jsfiddle.net/posgarou/S96zw/ 这是针对b页的http://jsfiddle.net/posgarou/S96zw/

HTML <body> <textarea id="result"></textarea> <button type="button" id="return" onClick="reply_click(this.id)">Return</button> </body> HTML <body> <textarea id="result"></textarea> <button type="button" id="return" onClick="reply_click(this.id)">Return</button> </body>

You should be able to do that using either a cookie or (better) local/sessionStorage. 您应该能够使用Cookie或(更好的)本地/会话存储来做到这一点。

On page b, you would include the following code: 在页面b上,您将包括以下代码:

sessionStorage["focusedButton"] = "buttonId";

and on page a, you would include the following: 在第a页上,您将包括以下内容:

if (sessionStorage["focusedButton"] != undefined) {
    document.getElementById(sessionStorage["buttonId"]).focus();
}

For more info, see this earlier question . 有关更多信息,请参见前面的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM