使用javascript操作gridview内部的文本 [英] Manipulate text in textbox which is inside gridview using javascript

查看:64
本文介绍了使用javascript操作gridview内部的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何删除焦点上的文本并从网格视图行内的文本框中恢复模糊文本?我不想使用按钮。只需单击文本框即可删除文本,失去焦点时,文本将被恢复。

文本框的值会有所不同,并在grid_rowDataBound事件期间设置。

这些是我的问题:

1.如何获得gridview的行号?

2.如何获取文本框的ID?

3.在哪里绑定javascript?



我尝试过:



i试过:



功能焦点()

{

document.getElementById(txtbox) .value =;

}





但是发现id正在改变。

解决方案

参考此示例



 <   html  >  
< head >
< script src = jquery.js > < / script >
< script >


function (){

var initialValue = ' ';


.TextBoxBlurEffect).on(' focus' function (){
initialValue = this .value;
.value = ' ';
})。on(' blur' function (){
var value = this .value;
if (value == ' '
this .value = initialValue;
});


});

< / script >

< / head >
< 正文 >

< 表格 id = form1 runat = server >
< asp:GridView runat = server ID = < span class =code-keyword> gv
AutoGenerateColumns = false >
< >
< asp:TemplateField HeaderText = 测试 >
< ItemTemplate >
< asp:TextBox ID < span class =code-keyword> =
txtbox1 CssClass = TextBoxBlurEffect 文字 = NA runat = server > < / asp:TextBox >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
< / asp:GridView >

< /表格 >


< / body >
< / html >





 受保护 < span class =code-keyword> void  Page_Load( object  sender,EventArgs e)
{
if (Page.IsPostBack) return ;
gv.DataSource = new int [] { 1 2 3 4 5 };
gv.DataBind();

}







demo:JSFiddle [ ^


Hi,

How can I remove text on focus and restore text on blur from a text box which is inside a gridview row? I do not want to use a button. Just click on text box removes the text and on losing focus, text will be restored.
The values of the textboxes vary and are set during the grid_rowDataBound event.
These are my questions:
1. How can I get the row number of gridview?
2. How can I get the id of the textbox?
3. Where to bind the javascript?

What I have tried:

i tried:

function focus()
{
document.getElementById("txtbox").value="";
}


But found that the id is changing.

解决方案

refer this sample

<html>
<head>
    <script src="jquery.js"></script>
    <script>


(function () { var initialValue = '';


(".TextBoxBlurEffect").on('focus', function () { initialValue = this.value; this.value = ''; }).on('blur', function () { var value = this.value; if (value == '') this.value = initialValue; }); }); </script> </head> <body> <form id="form1" runat="server"> <asp:GridView runat="server" ID="gv" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Test"> <ItemTemplate> <asp:TextBox ID="txtbox1" CssClass="TextBoxBlurEffect" Text="NA" runat="server"> </asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body> </html>



protected void Page_Load(object sender, EventArgs e)
       {
           if (Page.IsPostBack) return;
           gv.DataSource = new int[] {1,2,3,4,5 };
           gv.DataBind();

       }




demo:
JSFiddle[^]


这篇关于使用javascript操作gridview内部的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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