如何使用Javascript查找特定的隐藏HTML标记

时间:2014-04-23 05:52:50

标签: javascript jquery html

如何查找覆盖特定的隐藏 HTML标记(这将以鼠标悬停方式显示)为<a>标记title="Add"evtid="new_item"并使用Javascript和jQuery将href元素替换(不使用setAttribute)到​​href="something goes here"

HTML:

<div id="AsynchronousViewDefault_CalendarView">
<div class="ms-acal-header">
    <div>
        <table class="ms-acal-month">
        </table>
        <div class="ms-acal-vlink">
            <table>
                <tbody>
                    <tr>
                        <td><a href="javascript:void(0)" title="Add" evtid="new_item">
                            <img border="0" src="/_layouts/images/caladd.gif">Add</a></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

我的代码在这里:

 _spBodyOnLoadFunctionNames.push("OpenDialog1");
 $(document).ready(function OpenDialog1() {
    var nnnn = $("#AsynchronousViewDefault_CalendarView");
        var element = nnnn.querySelector('[title="Add"]');
        element.replace("javascript:void(0)", "http://share/Lists/Calendar.aspx?P=P1");

});

2 个答案:

答案 0 :(得分:2)

尝试,

$("#AsynchronousViewDefault_CalendarView")
    .find('a[title="Add"][evtid="new_item"]')
      .attr('href',"http://share/Lists/Calendar.aspx?P=P1");

DEMO

答案 1 :(得分:1)

$(document).ready(function () {
   $("a[href='javascript:void(0)']").attr('href', 'http://share/Lists/Calendar.aspx?P=P1');
});