动态插入的锚标签不起作用

时间:2017-07-03 09:44:51

标签: javascript jquery html anchor

我从jquery追加锚标记。点击此锚标签时,什么都不做。我尝试将锚更改为div并添加了onclick事件。但它没有用。

HTML:

SELECT * from table where id in 
( SELECT id FROM table group by id having count(id) > 1 )

脚本:

    <li class="list">
        <div class="dropdown" data-load="true">
        <span class="dropdown-toggle"></span>
            <ul class="dropdown-menu" role="menu">
                <li>
                    <span class="list-name" href="javascript:void(0);">
                        test
                    </span>
                </li>
            </ul>
        </div>
    </li>

输出:

    var element = $(".list").find("ul");
    var options = "";
    options += "<li><a class='list-name' href='www.test.com' target='_blank' data-toggle='tooltip' data-placement='top' data-original-title=''>" + "some value" + "</a></li>";
    element.html(options);

1 个答案:

答案 0 :(得分:0)

https://jsfiddle.net/anubala/kpgfgt74/

 var options = "";

options = "<li><a class='list-name' href='www.test.com' target='_blank' data-toggle='tooltip' data-placement='top' data-original-title=''>" + "some value" + "</a></li>";

$(&#34; .LIST&#34)。发现(&#34; UL&#34)的HTML(选项);