如何通过javascript访问asp.net mvc文本框中的文本? [英] How do I access the text within an asp.net mvc textbox via javascript?

查看:83
本文介绍了如何通过javascript访问asp.net mvc文本框中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过JavaScript访问asp.net mvc文本框中的文本?



基本上,我有2个文本框,你可以在下面看到我正在使用下面的javascript访问通过日期选择器选择并输出到文本框的文本,但到目前为止我所做的,似乎返回空值。







代码:



How do I access the text within an asp.net mvc textbox via JavaScript?

Basically, I have 2 textboxes which you can see below and I am using the javascript below to access the text selected via the date-picker and outputted to the textboxes but what I have done so far, seems to return null values.



Code:

@Html.Label("Start", "Start Date:")
@Html.TextBox("Start", string.Empty, new {@id = "Start2", @class = "datepicker"})
@Html.Label("endd", "End Date:")
@Html.TextBox("endd", string.Empty, new {@id = "End2", @class = "datepicker"})
<input type="submit" value="Apply" id ="DateSelected" />


<script type="text/javascript">
  $('.datepicker').datepicker();
$("#DateSelected").onclick(function () {
            var value1 = document.getElementById('<%=Start2.ClientID%>').value;
            var value2 = document.getElementById('<%=End2.ClientID%>').value;

</script>

推荐答案

' .datepicker')。datepicker();
('.datepicker').datepicker();


#DateSelected)。onclick(function(){
var value1 = document.getElementById(' <%= Start2.ClientID%>')。 value ;
var value2 = document.getElementById(' <%= End2.ClientID%>')。 value ;

< / script >
("#DateSelected").onclick(function () { var value1 = document.getElementById('<%=Start2.ClientID%>').value; var value2 = document.getElementById('<%=End2.ClientID%>').value; </script>


首先,我预计您正在使用jquery日期选择器。

所以我建议你使用ID而不是类。这仍然应该成功。当您在文本框中使用日期选择器时,可以通过以下方式获取该值:

First of all I am anticipating that you are using jquery date picker.
So I would recommend you to use ID for both instead of class. Still this should work out. As you are using date picker in textbox, that value can be obtained through..


这篇关于如何通过javascript访问asp.net mvc文本框中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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