Javascript - 从onclick获取innertext

时间:2017-09-04 17:48:35

标签: javascript jquery asp.net

我在ASP.net中有一个foreach循环

 <table id="Employee" class="table  table-responsive  table-bordered">
    <thead>
        <tr class="unselectable">
            <th>
                Selecteer folder:
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <a onclick="test(this)">@item.FolderName</a>
                </td>
            </tr>
        }
    </tbody>
</table>

现在这个结果出现在一个包含几个文件夹的表中,现在我想点击一个文件夹,然后将其发送到一个文本为item.Foldername作为参数的函数。

即: 我们有2个文件夹,FolderA和FolderB,我希望它能够点击FolderA,然后它转到javascript函数并添加“FolderA”作为参数。

function test(a) {
    alert(a);
}

像这样。

我不完全知道如何将特定项目的值作为参数。我已经完成了我的研究,并得出结论在onclick方法上使用(this),但由于某种原因它不起作用。我到底错在了什么?

1 个答案:

答案 0 :(得分:1)

您可以尝试使用textContent或innerHTML

import java.util.Scanner; // *Has to be outside of brackets!*

public class Lab_1_3_Class_oops {

    public static void main(String[] args) {

        //I need to request a person's first and last name, then copy it on individual lines after they have entered their input
        //Variables
        Scanner sc = new Scanner(System.in);

        //Requesting a name
        System.out.print("Please write your first and last name.\n");

        //Allowing a name input
        sc.nextLine();

        //I get as far as allowing text to be entered, but I can't figure out a way to keep that text in the memory long enough to get it copied 100 times without making the person type it 100 times
    }
}
相关问题