| |

VerySource

 Forgot password?
 Register
Search
View: 607|Reply: 2

Why can't the onload event of js fire?

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-9 11:30:01
| Show all posts |Read mode
<asp: DataList runat = "server" Id = "dlCategories" BorderWidth = "0" Width = "100%" GridLines = "Both" Bordercolor = "White" OnItemDataBound = "dlCategories_ItemDataBound" BorderStyle = "None">
                <ItemTemplate>
                    <table align = "center" border = "0" cellpadding = "0" cellspacing = "0" width = "130">
                        <tr>
                            <td background = "../ images / left_01.jpg" style = "height: 26px">
                                <table align = "center" border = "0" cellpadding = "0" cellspacing = "0" width = "98%">
                                    <tr>
                                        <td width = "20" style = "height: 29px">
                                            <img border = "0" height = "29" onload = "javascript: Getid (this)" src = "../ images / plus.gif" width = "20" /> </ td>
                                        <td style = "height: 29px; text-align: center">
                                            <table border = "0" cellpadding = "0" cellspacing = "0" width = "100%">
                                                <tr>
                                                    <td style = "height: 4px">
                                                    </ td>
                                                </ tr>
                                            </ table>
                                            <asp: Label ID = "Label1" runat = "server" onClick = "javascript: HiddenOrShow (document.getElementById ('img1'))" Text = '<% # DataBinder.Eval (Container, "DataItem.level1_name")% > 'Font-Size = "Small" ForeColor = "White" Font-Bold = "True"> </ asp: Label> </ td>
                                    </ tr>
                                </ table>
                            </ td>
                        </ tr>
                        <tr style = "color: # 0000ff; text-decoration: underline">
                            <td id = "tr_img0" onload = "javascript: Gettdid (this)" valign = "bottom">
                          </ ItemTemplate>
                <HeaderStyle BackColor = "# DDDDDD" Font-Bold = "True" Font-Names = "Arial" Font-Size = "14pt"
                    ForeColor = "# 777777" />
            </ asp: DataList>

-------------------------------------------------- -----------
var checkid = 0;
var countid = 0;
function Getid (obj)
{
if (checkid == countid)
    {
        checkid = checkid + 1;
        countid = countid + 1;
        var b = "img" + countid;
        obj.id = b;
    }
}
var checkid2 = 0;
var countid2 = 0;
function Gettdid (obj)
{
if (checkid2 == countid2)
    {
        countid2 = countid2 + 1;
        checkid2 = checkid2 + 1;
        var b = "tr_img" + countid2;
        obj.id = b;
        var a = obj.id;
        alert (a);
    }
}
-------------------------------------------------- -------------
There is a table in my datalist, and multiple tables are filled to generate multiple tables. I want to make an auto-sequenced id for td with id = "tr_img0" in the table.For example, if there are two data, then this td The ids are tr_img1 and tr_img2, but the onload event in this td is not like the other <img border = "0" height = "29" onload = "javascript: Getid (this)" src = "../ images / plus .gif "width =" 20 "/> is triggered like onload, how can I achieve my purpose?
Reply

Use magic Report

0

Threads

32

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-31 18:00:01
| Show all posts
Because there are no events, <td id = '<% # Container.ItemIndex + 1%>' value = "xx"> try it
Reply

Use magic Report

0

Threads

32

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-31 20:15:04
| Show all posts
There is no onload event for td.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list