单击时如何获得td值 [英] how to get a value of td when it is clicked

查看:98
本文介绍了单击时如何获得td值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的桌子

i''m having table like this

 Response.Write("<table>")
        While intstartrecord <= intrecordcount
Response.Write("<tr>")
Response.Write("<td id="columno" onclick=''showvalue()'' value=" & intstartrecord & ">" & intstartrecord & "</td>")
           intstartrecord = intstartrecord + 1
           Response.Write("</tr>")

         End While
 Response.Write("</table>")


function showvalue()
{
alert(document.GetElementById("columnno").value)
}



在这种情况下,当我单击任何列时,我都需要获取该值.当我使用此代码时,只要单击任何列,即得到相同的值,即无法识别单击的列.

我尝试过getval(this)和googled,但我没有得到我想要的东西

请帮助我做到这一点.



In this When i click on any column i need to get that value. when i use this code i''m getting the same value whenever i clicked on any column ie., it is not recognizing the clicked column.

i tried getval(this) and googled but i''m not getting what i want

Please help me to do this

推荐答案

我在C#中实现了小功能,但我想您应该能够轻松将其更改为VB.这正在按您的预期进行.告诉我,如果您特别需要使用ID使其正常工作,我也可以这样做.

这是该代码背后的代码

I implemented the small thing in C# but i guess you shuold be able to change it to VB easily. This is working as you expected it to be. Tell me if you specifically need to make it work using IDs i can do that too.

here is the code behind for that

protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<table>");

        int intstartrecord = 0;
        int intrecordcount = 10;

        while (intstartrecord <= intrecordcount)
        {
            Response.Write("<tr>");
            Response.Write(@"<td id='columno' onclick='showvalue(this)' value=" + intstartrecord + ">" + intstartrecord + "</td>");
            intstartrecord++;
           Response.Write("</tr>");


        }
        Response.Write("</table>");
    }



这是我放在aspx文件中的javascript函数



and here is the javascript function i put in the aspx file

<script type="text/javascript">
    function showvalue(sender)
    {
        alert(sender.value);
    }
</script>



最后的提示:使用字符串生成器来裁剪完整的字符串,然后只做一次response.write,那样会更好.



On a closing note: use string builder to tailor the complete string and then do response.write only once that would be better.


请检查您的ID td..it对于所有列都是相同的.这就是为什么它为每个列返回相同的值.


谢谢
Ashish
please check the id of your td..it is same for all the columns..thats why it is returning the same value for every column.


Thanks
Ashish


使用ID数组分隔td ID:

Use array of id to separate the td id:

Response.Write("<td id="columno[intstartrecord]" onclick=''showvalue()'' value=" & intstartrecord & ">" & intstartrecord & "</td>")



谢谢,
Elangovan



Thanks,
Elangovan


这篇关于单击时如何获得td值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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