如何设置非CSS属性 [英] how to set non-CSS properties

查看:81
本文介绍了如何设置非CSS属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在css文件中设置CSS属性,并将其应用于整个站点。对于输入文本类型,非CSS属性如maxlength如何?我们如何设置它们?

解决方案

我建​​议使用主题。



1.在网络根目录中添加一个名为app_themes的文件夹(如果它还没有)。



2.在该文件夹中添加名为MyTheme的文件夹。



3.在MyTheme文件夹中添加皮肤文件(右键单击文件夹并选择添加>> ;新项目。来自对话框选择皮肤)。



4.在皮肤文件中输入:



< asp:TextBox runat =''sever''MaxLength =''100''/>



请注意,此处未设置ID等实例变量。



5.在< system.web>下设置的web.config中。添加< page theme =''MyTheme''/>



这将使所有文本框的maxlength = 100.如果只想要一个页面,不要在网络配置中设置它。在页面顶部的@Page指令中,设置theme =''MyTheme''



我在这里找到了这个 http://www.dotnetspider.com/forum/204101-How-set-maxlength-property-textbox- using-css.aspx [ ^ ]


这些不是属性。它们是属性,与XML属性相同。



显然,你看看HTML标准并写相应的;广义语法类似于XML:< someElement someAttributeName =some sometribite value...> ...... 。这适用于ASP.NET / HTML。



您可以使用 element.setAttribute() element.someAttributeName =some sometribite value

http://www.w3schools.com/dom/met_element_setattribute.asp [ ^ ]。



我强烈建议使用jQuery:http://api.jquery.com/category/attributes/ [ ^ ]。



如果您需要学习jQuery,请从这里开始:

http://en.wikipedia.org/wiki/Jquery [ ^ ],

http://docs.jquery.com/Tutorials [ ^ ],

http://docs.jquery.com / How_jQuery_Works [ ^ ]。



-SA


您可以使用全局变量,在_AppStart.cshtml文件中初始化它们,并在需要时调用它们。

尝试在Webmatrix网站的根目录下创建一个新的 _AppStart.cshtml 文件,其中包含以下内容:

 @ {
AppState [ mlen] = < span class =code-digit> 10 ;
}



现在用这个内容创建一个 Default.cshtml 文件:

 @ {
var mlen = AppState [mlen];
}



< html lang = zh >
< < span class =code-leadattribute> body >
< 表格 >
< 输入 type = text maxlength = @ mlen / >
< / form >
< / body >
< / html >



您的输入字段的maxlengh为10,因此您使用属性的任何其他字段 maxlength =@ mlen


CSS properties can be set in a css file and be applied in the whole site. How about non-CSS properties like maxlength for input type of text. How can we set them in general?

解决方案

I would suggest using a Theme then.

1. Add a folder called app_themes in the web root (if it''s not already there).

2. Add a folder called MyTheme in that folder.

3. In the MyTheme folder add a skin file (right click folder and select add>>new item. from dialog select skin).

4. In the skin file put this in:

<asp:TextBox runat=''sever'' MaxLength=''100'' />

Note that no instance variables like ID are set here.

5. In web.config set under <system.web> add <page theme=''MyTheme'' />

This will make all textboxes have maxlength = 100. If you want it only for a single page, don''t set that in the web config. In the @Page directive at the top of the page, set theme=''MyTheme''

I found this herehttp://www.dotnetspider.com/forum/204101-How-set-maxlength-property-textbox-using-css.aspx[^]


Those are not "properties". They are "attributes", same as XML attributes.

Obviously, you look at HTML standard and write the accordingly; generalized syntax is like in XML: <someElement someAttributeName="some attribite value" …> …. This is for ASP.NET/HTML use.

You can add/modify any attribute in JavaScript, using element.setAttribute() or element.someAttributeName = "some attribite value":
http://www.w3schools.com/dom/met_element_setattribute.asp[^].

I would highly recommend to use jQuery: http://api.jquery.com/category/attributes/[^].

If you need to learn jQuery, please start here:
http://en.wikipedia.org/wiki/Jquery[^],
http://docs.jquery.com/Tutorials[^],
http://docs.jquery.com/How_jQuery_Works[^].

—SA


You could use global variables, initializing them in the _AppStart.cshtml file an recalling them when you want.
Try to create in the root of your Webmatrix site a new _AppStart.cshtml file with the following content:

@{
    AppState["mlen"] = 10;
}


Now create a Default.cshtml file with this content:

@{
    var mlen = AppState["mlen"];
}



<html lang="en">
    <body>
        <form>
            <input type="text" maxlength="@mlen" />
        </form>
    </body>
</html>


Your input field has a maxlengh of 10 and so any other field in which you use the attribute maxlength="@mlen".


这篇关于如何设置非CSS属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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