到目前为止,我有以下代码。
index.js
var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var self = require("sdk/self");
var button = ToggleButton({
id: "my-button",
label: "seedXXX.in",
icon: {
"16": "./icon.png",
"32": "./icon_48.png",
"64": "./icon_128.png"
},
onChange: handleChange
});
var panel = panels.Panel({
contentURL: self.data.url("popup.html"),
onHide: handleHide
});
function handleChange(state) {
if (state.checked) {
panel.show({
position: button
});
}
}
function handleHide() {
button.state('window', {checked: false});
}
的package.json
{
"title": "seedXXX.in (DE)",
"name": "seed-XXXde",
"version": "1.0.0",
"description": "XXX",
"main": "index.js",
"author": "XXX",
"permissions": {
"cross-domain-content": ["https://seedXXX.in"]
},
"engines": {
"firefox": ">=38.0a1",
"fennec": ">=38.0a1"
},
"license": "MIT"
}
popup.html
<!doctype html>
<html>
<head>
<title>seedXXX.in</title>
<link href="css/plugin.css" type="text/css" rel="stylesheet">
<link href="libs/css/font-awesome.css" type="text/css" rel="stylesheet">
<script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
<center><a href="https://seedXXX.in/" target="_blank"><img src="https://seedXXX.in/img/logo.png"></a>
<hr>
<input class="formField" type="text" placeholder="Strain Suchen..." maxlength="50" name="keyword" id="keyword" required><br><div id="suggesstion-box"></div>
<hr>
<button class="btn" onclick="doSearch()"><i class="fa fa-search"></i> Suchen</button>
</center>
<script>
function doSearch() {
// check if keyword is not empty
if(document.getElementById('keyword').value != '') {
// set variables and do the search
var strainName = document.getElementById('keyword').value;
var urlEncode = encodeURIComponent(strainName);
var replaced = urlEncode.replace(/%20/g, "+");
var searchURL = "https://seedXXX.in/searchstrain.php?keyword="+replaced+"&lang=de";
// do the search
window.open(searchURL, '_blank');
}else{
// focus if 'keyword' is empty
document.getElementById("keyword").className = "formField fieldEmpty";
document.getElementById("keyword").focus();
setTimeout(function(){ document.getElementById("keyword").className = "formField"; }, 1500);
}
}
</script>
</body>
</html>
直到现在一切都很好,在我...部分我想添加以下内容(这适用于网站和Chrome没有任何问题):
// liveSearch
$(document).ready(function(){
$("#keyword").keyup(function(){
$.ajax({
type: "POST",
url: "https://seedXXX.in/ajax_apps.php",
data:'keyword='+$(this).val(),
beforeSend: function(){
//$("#keyword").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
},
success: function(data){
$("#suggesstion-box").show();
$("#suggesstion-box").html(data);
$("#keyword").css("background","#FFF");
}
});
});
});
如果我将此部分放入popup.htmt中,则无法在keyup上显示任何内容。任何人都可以帮助我(noob :))有这个问题让这个工作吗?
提前致谢。