2011-10-17 7 views
0

JavaScriptでボタンが作成されており、キーボードのアクセシビリティにTabIndexを追加したいと考えています。JavaScriptで作成されたボタンにTabIndexを追加

button41 = new ObjButton('button41',null,679,0,53,32,1,54,'div') 
button41.setImages('images/0807_help.jpg','images/0807_help_over.jpg','images/0807_help_over.jpg') 
button41.onUp = button41onUp 
button41.hasOnUp = true 
button41.capture=4 
button41.setAccessKey(2) 
button41.setTabIndex(2) 
button41.build() 

しかし、私はのTabIndexを追加しようとしたとき、のTabIndex番号は動作しませんでした:私はこのコードでこのコードでアクセスキー値を追加しました。助言がありますか?スクリプトは次のとおりです。

function ObjButtonBuild() { 
    this.css = buildCSS(this.name,this.x,this.y,this.w,this.h,this.v,this.z) 
    this.div = '<' + this.divTag + ' id="'+this.name+'" style="text-indent:0;"></' + this.divTag + '>\n' 
    this.divInt = '<a name="'+this.name+'anc" href="javascript:void(null)"' 
    if(this.accessKeyValue && this.accessKeyValue!=null) { 
     this.divInt+=' accessKey='+this.accessKeyValue+' '; 
    } 
    if(this.altName) 
     this.divInt += ' title="'+this.altName+'"' 
    else if(this.altName != null) 
     this.divInt += ' title=""' 
     this.divInt += '><img name="'+this.name+'Img" src="'+this.imgOffSrc 
    if(this.altName) 
     this.divInt += '" alt="'+this.altName 
    else if(this.altName != null) 
     this.divInt += '" alt="' 
     this.divInt += '" width='+this.w+' height='+this.h+' border=0' 
    if(!is.ns4) 
     this.divInt += ' style="cursor:pointer"' 
     this.divInt += '></a>' 
} 
+0

jQueryのは、あなたのコードははるかに良くなるだろう。 – ThiefMaster

答えて

2

このように要素を組み立てるべきではありません。代わりにdocument.createElement()を使用してください:

var el = document.createElement("a"); 
if (el){ 
    el.name = "foo"; 
    el.href = "somepage.htm"; 
    el.tabIndex = 3; 
} 

ます。また、このようにそれを行うことができます。

var el = document.createElement("a"); 
if (el){ 
    el.setAttribute("class", "someclass"); 
    el.setAttribute("name", "foo"); 
    el.setAttribute("href", "somepage.htm"); 
    el.setAttribute("tabIndex", "3"); 
} 

ます。また、このためにjQueryを使用することができます。

var el = $("<a>", { name : "foo", href : "somepage.htm", tabIndex : "6" }); 
関連する問題