将 TabIndex 添加到 JavaScript 构建的按钮

发布于 2024-12-10 03:18:41 字数 1469 浏览 1 评论 0原文

我有使用 JavaScript 构建的按钮,并且想要添加 TabIndex 以实现键盘可访问性。我在这段代码和这段代码中添加了accesskey值:

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>'
}

I have buttons built with JavaScript and want to add TabIndex for keyboard accessibility. I added accesskey values in this code and in this code:

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()

But when I tried to add TabIndex, the TabIndex number didn't work. Any suggestions? Here is the script:

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>'
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生一个溪 2024-12-17 03:18:41

您不应该以这种方式构建元素。使用 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" });

You shouldn't be building your elements that way. Use document.createElement() instead:

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

You can also do it this way:

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

You can also use jQuery for this:

var el = $("<a>", { name : "foo", href : "somepage.htm", tabIndex : "6" });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文