代码如下:
var w=document.querySelector('body > div:nth-child(1)');
function find(){
var now = window.location.pathname;
if(now[1]!='p'){
window.alert('请打开题目页面后点击此按钮');
}else{
var b=document.querySelector('#main > div.ui.center.aligned.grid > div:nth-child(1) > h1');
b=b.innerHTML;
var e,h=' ';
for(var i=0;i<b.length;i=i+1){
if(b[i]==':' || b[i]==':'){
e=i;
break;
}
}
e=e+2;
while(e<b.length){
h=h+b[e];
e=e+1;
}
//window.alert(h);
window.open('https://www.luogu.com.cn/problem/list?keyword='+h);
}
}
var s='\xa0 <a class="small ui yellow button" onclick="find()">在洛谷里找找这题</a>';
w.innerHTML=s;
倒数第二行中当按钮被点击使用一个函数,可也许是因为 html 中没有描述这个函数的 标签,所以没法用这个函数,怎么解决,难道要把整个函数 innnerHTML 到想插入的地方吗 qwq