通过Javascript更改属性 [英] Change attribute through Javascript

查看:86
本文介绍了通过Javascript更改属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在尝试在VB Page_Load部分中调用javascript函数.目前,我必须通过使用警报进行响应.我的问题是如何将可见性属性更改为我的按钮之一.当我尝试执行以下操作时:

Currently I am trying to call a javascript function in the VB Page_Load part. Currently I have got to respond through using alerts. My question is how can I change the visibility attribute to one of my buttons. When I try to:

var rawr = document.getElementById('OPENSEHMMSID');
rawr.setAttribute("visible", false);
alert(rawr.getAttribute("visible"))


我的警报将其设置为false,但是我仍然在页面中看到该按钮.此javascript函数当前位于头部.任何人都知道如何使该属性正常工作吗?


My alert gives that it is set to false but I still see the button in my page. This javascript function is currently in the head. Anyone know how to make the attribute to work?

推荐答案

我建​​议您更喜欢更改样式属性而不是可见性,以使您的代码在编写时更加通用和规范获得更多的细粒度控制.另外,我建议您使用jQuery.

请参阅jQuery方法.addClass().removeClass().toggleClass()和其他CSS方法:
http://api.jquery.com/category/css/ [ http://api.jquery.com/addClass/ [ http://www.w3schools.com/css/css_display_visibility.asp [
I would advise that you prefer changing the style attribute instead of visibility, to make you code more universal and regular while gaining more fine-grain control. Also, I would advise you do it using jQuery.

Please see the jQuery methods .addClass(), .removeClass(), .toggleClass() and other CSS methods:
http://api.jquery.com/category/css/[^].

You can find a code sample here:
http://api.jquery.com/addClass/[^].

The CSS property you would need to operate would be visibility; please see:
http://www.w3schools.com/css/css_display_visibility.asp[^].

As a rule of thumb, if some effect can be achieved both through CSS and from more specialized attibutes, CSS approach should be preferred. It will help you to have more supportable code because extra flexibility and isolation between code and style will make possible changes less painful.

—SA


这篇关于通过Javascript更改属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆