私はボタンの拡大と折り畳みに取り組んでいます。私はここに2つの画像があり、フォーカスは要素にとどまるべきです。一度クリックすると、collapse
となり、別のクリックはexpand
となります。私は要素をフォーカスしようとしましたが、.focus()
は機能しません。ボタンを展開して折り畳むjavascript
HTML:
<td aria-expanded="false" name="td_tohide2" id="td_tohide2" style="padding:0px;" class="sectiontd" nowrap="true" >
<img role="button" aria-labelledby="hide_show" id="generalinfo_caretup" src="images/arrow_up_ps_oc.png" onkeypress="sh_keypress('td_tohide2','td_toshow2','generaltable',event)" onclick="sh('td_tohide2','td_toshow2','generaltable')" tabindex="0" />
</td>
<td aria-expanded="true" aria-labelledby="hide_show_" name="td_toshow2" id="td_toshow2" style="padding:0px;display:none" class="sectiontd" nowrap="true">
<img role="button" id="generalinfo_caretdown" src="images/arrow_down_ps_oc.png" onkeypress="sh_keypress('td_toshow2','td_tohide2','generaltable',event)" onclick="sh('td_toshow2','td_tohide2','generaltable')" tabindex="0" />
</td>
Javascriptを:
function sh_keypress(a,b,c,event){
if(event.keyCode==13 || event.keyCode==32 || event.which==13 || event.which==32) {
if(document.getElementById(c).style.display=="none")
document.getElementById(c).style.display = "";
else
document.getElementById(c).style.display = "none";
document.getElementById(a).style.display="none"; //arrow images
document.getElementById(b).style.display=""; //arrow images
setTimeout("document.getElementById(b).focus()",1000);
event.stopImmediatePropagation();
}
}
function sh(a,b,c)
{
if(document.getElementById(c).style.display=="none")
document.getElementById(c).style.display = "";
else
document.getElementById(c).style.display = "none";
document.getElementById(a).style.display="none"; //arrow images
document.getElementById(b).style.display=""; //arrow images
}
誰がどのように要素を集中することができますアイデアを与えることができます。
もっと完全なコードサンプルを共有できますか?コードの一部しか共有していないようです。 –
私はhtmlとjsの両方の機能を共有しました – anu
あなたはフォーカスを言う、フォーカスはあなたのようです。 setTimeoutに文字列を提供せず、実際の関数を提供します。 –