JavaScript函数仅在Developer Console中复制和粘贴时才有效,但不能从代码中复制和粘贴

问题描述 投票:0回答:1

我正在尝试编写一个Javascript函数,当单击按钮时应该触发它。问题是,当我在开发人员的控制台中复制Javascript函数而不是从代码中复制时,它工作正常。这是我的代码

速度代码:

  <body>

<table id="tablerows">
    <tbody>
    <tr id="tr1">
        <td class="checkbox"><input type="checkbox" value="yes"></td>
        <td>Item 1</td>
        <td>with data 1</td>
    </tr>
    <tr id="tr2">
        <td class="checkbox"><input type="checkbox" value="yes" ></td>
        <td>Item 2</td>
        <td>with data 2</td>
    </tr>
    <tr id="tr3">
        <td class="checkbox"><input type="checkbox" value="yes"></td>
        <td>Item 3</td>
        <td>with data 3</td>
    </tr>
    </tbody>
</table>



<button class="aui-button" id="test-button">Test</button>


<p id="out"></p>

</body>

Javascript代码:

AJS.$('#test-button').click(function () {

        AJS.log("I am inside test button function")
        $('#out').text('');
        $('#rowclick2 tr').filter(':has(:checkbox:checked)').each(function() {
            // this = tr
            $tr = $(this);
            $('td', $tr).each(function() {
                // If you need to iterate the TD's
            });
            //get row values
            $('#out').append(this.id);
        });

    })
javascript jquery velocity
1个回答
0
投票

您需要在正文末尾添加对外部javascript文件的引用,以确保您的按钮已存在于DOM中。

© www.soinside.com 2019 - 2024. All rights reserved.