在网站pib.nic.in/newsite/erelease.aspx中,左侧链接在同一页面中打开 - 不方便阅读和切换到下一个主题。
调用的函数Getrelease
传递与单击的项目相对应的唯一 ID,以获取并显示在右侧列中。
相关页面,HTML 片段是:
<div class="leftrightdiv" id="lreleaseID">
<ul class="link1">
<li style="list-style:none;border-bottom: blue 1px dotted;color:blue;font-size:110%" class="rel">Prime Minister's Office</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" **onclick='Getrelease(94318)'** >PM's statement at the BRICS Leaders - Africa Dialogue Forum<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="Getrelease(94318)" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">PM's statement at the BRICS Leaders - Africa Dialogue Forum</li>
<li style="list-style:none;border-bottom: blue 1px dotted;color:blue;font-size:110%" class="rel">Ministry of Finance</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94339)' >Central Board of Excise and Customs (CBEC) Offices to Remain open on 29th, 30th & 31stmarch, 2013 ;<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="Getrelease(94339)" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">Central Board of Excise and Customs (CBEC) Offices to Remain open on 29th, 30th & 31stmarch, 2013 ;</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94338)' >India and Liechtenstein Sign Tax Information Exchange Agreement (TIEA)<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="Getrelease(94338)" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">India and Liechtenstein Sign Tax Information Exchange Agreement (TIEA)</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94337)' >Government Committed to bring down the Current Account<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="Getrelease(94337)" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">Government Committed to bring down the Current Account</li>
</ul>
<br>
</div>
我想将以上内容更改为以下代码,以便在单击该项目时,它将在新页面中打开。
<div class="leftrightdiv" id="lreleaseID">
<ul class="link1">
<li style="list-style:none;border-bottom: blue 1px dotted;color:blue;font-size:110%" class="rel">Prime Minister's Office</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94318)' >PM's statement at the BRICS Leaders - Africa Dialogue Forum<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="window.open('http://www.pib.nic.in/newsite/erelease.aspx?relid=94318')" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">PM's statement at the BRICS Leaders - Africa Dialogue Forum</li>
<li style="list-style:none;border-bottom: blue 1px dotted;color:blue;font-size:110%" class="rel">Ministry of Finance</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94339)' >Central Board of Excise and Customs (CBEC) Offices to Remain open on 29th, 30th & 31stmarch, 2013 ;<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="window.open('http://www.pib.nic.in/newsite/erelease.aspx?relid=94339')" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">Central Board of Excise and Customs (CBEC) Offices to Remain open on 29th, 30th & 31stmarch, 2013 ;</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94338)' >India and Liechtenstein Sign Tax Information Exchange Agreement (TIEA)<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="window.open('http://www.pib.nic.in/newsite/erelease.aspx?relid=94338')" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">India and Liechtenstein Sign Tax Information Exchange Agreement (TIEA)</li>
<!-- <li class="rel" style="border-bottom: teal 1px dotted;cursor:pointer" onclick='Getrelease(94337)' >Government Committed to bring down the Current Account<span style='font-weight:lighter;color: ThreeDDarkShadow;'> ()</span></li> -->
<li onclick="window.open('http://www.pib.nic.in/newsite/erelease.aspx?relid=94337')" style="border-bottom: teal 1px dotted;cursor:pointer" class="rel">Government Committed to bring down the Current Account</li>
</ul>
<br>
</div>
所以写了这个 Greasemonkey 脚本:
// ==UserScript==
// @name Press Information Bureau
// @namespace http://userscripts.org/scripts/show/163329
// @description PIB new tab open
// @include http://pib.nic.in*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @version 2.4
// ==/UserScript==
function replaceOnclick() {
var list = document.getElementById('lreleaseID');
var lists = list.getelementsbytagname('li');
for (i = 0; i < lists.length; i++) {
var Str = lists[i].getAttribute("onclick");
var seconds = Str.indexOf(')');
var url = "http://www.pib.nic.in/newsite/erelease.aspx?relid=" + Str.substring(11, second);
lists[i].setAttribute("onclick", "window.open('" + url + "')");
}
}
Greasemonkey 脚本正在被注入。但它没有在输出中做出预期的变化。
javascript使用中的错误是什么?请帮助我。