如何访问控制,我们有它的id [英] How can access the control that we have it's id

查看:129
本文介绍了如何访问控制,我们有它的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页隐藏的输入,它包含另一个输入控件的ID。
现在怎么可以访问特定的输入控件,它的ID是我隐藏输入值白衣JQuery的?

I have a hidden Input in my web page that it contains another Input control's Id. now how can access to the specific Input controls that it's id is in my hidden input value whit JQuery?

<input type="hidden" id="edBuyMeal" runat="server" value="BtnId" enableviewstate="False" />


function SetBuyAttr(s) {debugger
    var Attr = s.split('^');
    var btn ="'#'" +$("#" + $("#edBuyMeal").val());
    $(btn).css("color","red");
}

我在jQuery的初学者。

I'm beginner in Jquery.

推荐答案

在ASP.NET和标准的JavaScript你会发现隐藏字段是这样的:

In ASP.NET and standard javascript you would find the hidden field like this:

var btn = document.getElementById("<%:edBuyMeal.ClientID%>");

您code尚不清楚,但现在看来,你是从隐藏字段获取值,该值是一个按钮的ID,然后设置CSS类按钮。

Your code is unclear, but it appears that you are getting the value from the hidden field, the value being the id of a button, then setting the css class of that button.

这应该是这样的:

var hidden = document.getElementById("<%:edBuyMeal.ClientID%>");
var btnId = hidden.val();

ASP.NET的更改元素的Id的。任何与 =服务器您需要确保的ClientIDMode =静态设置为 BtnId 。这将允许你添加CSS类是这样的:

ASP.NET changes the Id's of the elements. Anything with runat="server" you will need to make sure that ClientIDMode="Static" is set for BtnId. This will allow you to add a css class like this:

$(btnId).addClass("myRedClass");

虽然JavaScript的速度会更快,如果你想这样做在JQuery中它是这样的:

While javascript will be faster, if you want to do it in JQuery it would look like this:

    var hidden = $("#<%:edBuyMeal.ClientID%>");

这篇关于如何访问控制,我们有它的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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