我的问题是如何把这个:
function setTextColor(picker) {
document.getElementsByTagName('agario-panel')[0].style.color = '#' + picker.toString()
在html和this中:
panelPlusK.append("<button class="jscolor {valueElement:'chosen-value', onFineChange:'setTextColor(this)'}">Pick Menu Color </button>");
我尝试使用jquery但是当我把这两个代码中的一个放入时,js文件就不会加载。
这是我的代码:
$( "div" ).remove( ".ogario-yt-panel" );
$( "div" ).remove( "#ogario-ad" );
$( "div" ).remove( "#version" );
$( "h2" ).remove( ".main-color" );
$( "h1" ).remove();
$( "#s300x250" ).remove();
$( "#socialStats" ).replaceWith('<div id="socialStats" style="position: absolute;bottom: 70px;left: 25px;right:25px;"><button id="gPlusShare" style="width:49%;float:left;display:none" class="g-interactivepost btn btn-primary btn-gplus" data-contenturl="http://agar.io" data-clientid="" data-cookiepolicy="http://agar.io" data-prefilltext="" data-calltoactionlabel="BEAT" data-calltoactionurl="http://agar.io"><span class="gplus-icon"></span><span class="btn-text" data-itr="share">Share</span></button><button id="fbShare" class="btn btn-primary btn-fb" onclick="fbShareStats(); return false" style="position:relative;width:49%;float:left;"><span class="social social-facebook fb-icon"></span><span class="btn-text" data-itr="share">Share</span></button><button class="btn btn-primary btn-twitter" onclick="twitterShareStats(); return false" style="position:relative;width:49%;float:right"><span class="twitter-icon"></span><span class="btn-text" data-itr="share">Share</span></button></div>');
$( "#statsContinue" ).replaceWith('<button id="statsContinue" class="btn btn-primary" data-itr="continue">Continue</button>')
$("#mainPanel").before('<div id="harryext" style="/* background-color: rgba(133, 58, 182, 0); */margin-top: 2px;width: 340px;margin-left: 4px;border-bottom: 2.5px solid #ff0202;font-size: 25px;padding: 5px;font-weight: 600;color: #E91E63;margin-bottom: 7px;" align="center">HarrY ExT</div>');
$( "#leaderboard-hud h4" ).replaceWith( "<div class='header'>HarrYExt V.1</div>" );
$( "div" ).remove( "#leaderboard-hud" );
$(".party-panel").after('<div id="PrivateServersPanel" class="agario-panel agario-side-panel"><select id="PrivateServer" class="form-control privateServer" style="height: 35px; display: block; width: 100%; float: left; margin-bottom: 10px;"><option value="Private Servers" disabled="" default="" selected="" style="display: none;width:100%">Private Servers</option><option value="ws://parisgamma.iomods.com:1501">Private Party</option><option value="ws://82.11.47.60:443">Private Party (2)</option><option value="ws://185.38.150.94:443">W = Virus</option><option value="ws://vps56296.vps.ovh.ca:443">Huge Map + SelfFeed</option><option value="ws://vps62061.vps.ovh.ca:443">Juggernaut Mode</option><option value="ws://ffa1.unnamedcell.com:443">Unlimited Split</option><option value="ws://agario.willsr71.net:8080">Fast Merge</option></select><button class="btn btn-nosx joinPrivate1" style="height:35px;margin-bottom: 10px;width:100%;" onclick="$(\'.partyToken\').val($(\'#PrivateServer\').val()); connect($(\'#PrivateServer\').val());">Connect</button></div>');
$("#mainPanel").after('<div align="middle" id="Radio" class="RadioClass" style="display: block;width: 90%;margin-left: 16px;margin-top: 2px;"><audio style="width:100%;" controls="" src="http://192.99.0.170:5529/;"><a href="music.html" target="radio" align="middle"></a></audio></div>');
$("title").replaceWith('<title>HarryExT</title>');
$("#PrivateServersPanel").after('<div id="addMenuKontainer" class="agario-panel agario-side-panel" style="margin-bottom:0px !important"><div class="clear-menu-btnK"><input id="addMenuK" type="checkbox"><span class="topK"></span><span class="middleK"></span><span class="bottomK"></span><span class="circleK"></span></div><p style="text-align:center;color:#42A5F5">Some Options</p></div>');
$("#addMenuKontainer").after('<div id="additionalPanelK" class="agario-panel agario-side-panel" style="margin-top:0px;display:none;padding-top:0px !important;font-size:12px !important;font-family:Ubuntu"></div>');
$("#addMenuK").on("click",function(){
$("#additionalPanelK").toggle();
});
//Additional Settings Checks
var panelPlusK = $("#additionalPanelK");
var stSett = $(".col-xs-6.firstSettings");
panelPlusK.append("<br><input id='opt_privateServer' type='checkbox'> Hide Private Servers<br>");
var privatePanelK = $("#PrivateServersPanel");
if(JSON.parse(localStorage.getItem("opt_privateServer"))===true){
$("#opt_privateServer").prop("checked",true);
privatePanelK.hide();
} else if(JSON.parse(localStorage.getItem("opt_privateServer"))===false){
$("#opt_privateServer").prop("checked",false);
} else {
localStorage.setItem("opt_privateServer",false);
}
$("#opt_privateServer").change(function(){
if($(this).is(":checked")){
privatePanelK.hide();
localStorage.setItem("opt_privateServer",true);
} else {
privatePanelK.show();
localStorage.setItem("opt_privateServer",false);
}
});
panelPlusK.append("<input id='opt_radioK' type='checkbox'> Hide Radio<br>");
if(JSON.parse(localStorage.getItem("opt_radioK"))===true){
$("#opt_radioK").prop("checked",true);
$("#Radio").hide();
} else if(JSON.parse(localStorage.getItem("opt_radioK"))===false){
$("#opt_radioK").prop("checked",false);
} else {
localStorage.setItem("opt_radioK",false);
}
$("#opt_radioK").change(function(){
if($(this).is(":checked")){
$("#Radio").hide();
localStorage.setItem("opt_radioK",true);
} else {
$("#Radio").show();
localStorage.setItem("opt_radioK",false);
}
});
当我添加这两件事时,页面会加载js文件。
答案 0 :(得分:1)
我认为你的问题是:
"
无效的javascript。
如果您需要在其他引号内加引号,则必须将它们转义(而不是\"
,使用panelPlusK.append("<button class=\"jscolor {valueElement:'chosen-value', onFineChange:'setTextColor(this)'}\">Pick Menu Color </button>");
)。所以试一试:
function setTextColor(picker) {
document.getElementsByTagName('agario-panel')[0].style.color = '#' + picker.toString()
<强>更新强>
此外,它看起来像这段代码:
getElementsByClassName
需要一个结束括号(我认为你应该使用getElementsByTagName
而不是function setTextColor(picker) {
document.getElementsByClassName('agario-panel')[0].style.color = '#' + picker.toString();
}
),如下所示:
console.log()
这可能会解决你的第二个问题(在这个答案的评论中提到) - 但如果没有,我建议在无效的代码位上面添加一些function setTextColor(picker) {
console.log(document.getElementsByTagName('agario-panel')[0]);
console.log('#' + picker.toString());
document.getElementsByTagName('agario-panel')[0].style.color = '#' + picker.toString();
}
语句,试试这个:
cmd + shift + j
然后查看开发人员控制台(mac中的chrome {{1}})并查看日志。你应该看到两个,第一个是有问题的元素,第二个是你想要设置的颜色。
如果您没有看到您的期望,可以使用该信息进行调试。