【问题标题】:How to pass Textbox id in detailsview to JavaScript如何将详细信息视图中的文本框 ID 传递给 JavaScript
【发布时间】:2016-06-20 07:46:41
【问题描述】:

我应该在插入和编辑模式(在运行时 detailsview 模式会改变)中将文本框的 clientID 传递给 javascript,如下所示:

$('#textbox2').datepicker({
    ...
});

我该怎么做?谢谢。

【问题讨论】:

  • 您是否考虑过使用类来代替?

标签: javascript c# asp.net computer-science detailsview


【解决方案1】:

这里是,

$('#detailsview #TextBox2').val() 

For Example...

<div id="demo1">
    <div>
       <input type="text" id="txtOne"/>
    </div>
</div>
<div id="demo2">
    <div>
       <input type="text" id="txttwo"/>
    </div>
</div>

then you can find that  textbox like this..

$("#demo1 div #txtOne");

This is just demo it may help you to get idea that how its to be perform

or if you say that inside control will be change then you can also use by **class** or any **tag name** too..

【讨论】:

    【解决方案2】:

    有一个 .val() 方法:

    如果你有一个文本框的 clientID 输入,你可以使用下面的代码来访问文本框的值:

    $("#textbox").val()
    

    【讨论】:

    • 谢谢,不过这个案子比较复杂
    • 因为控件在另一个控件中并且它会改变,我必须使用一些代码,例如:$('#')({ ...})
    • $(document).ready(function () { $('select[id*=textbox1]').click(function () { alert("Hello world!"); }); });
    • 一旦你选择了文本框,你就可以得到值
    【解决方案3】:

    试试这个

    <asp:TextBox runat="server" id="textbox1"/>
    
    <script>
        $('#<%= textbox1.ClientID%>').datepicker({
            ...
        });
    </script>
    

    【讨论】:

    • 嗨,请考虑文本框在详细信息视图中
    【解决方案4】:
    <InsertItemTemplate> 
         <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("StartDate") %>'></asp:TextBox>
    </InsertItemTemplate>
    

    为此,您可以使用 like...

    $("InsertItemTemplate #TextBox2").val();    
    
    
    here, client side you can not get `**[InsertItemTemplate]**` so you can use that 
    control render in DIV so in place of InsertItemTemplate you use Div like
    
    $("div #TextBox2").val(); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-18
      • 2023-03-27
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      相关资源
      最近更新 更多