在一个项目中,我可以写一个文件,但在另一个项目我可以't、 真的很奇怪
In one project I can write a file but in the other I can't, really strange
在一个项目中,我设法用phonegap编写文件,工作方式如下:
$("#download").live("click", function(){
writeFile();
});
function writeFile(){
$.get("http://www.bartdekimpe.be/anoire/index.php/admin/getGamesUserJson/34", function(result){
json = result;
removeHTMLTags();
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
});
}
function removeHTMLTags(){
if(json){
var strInputCode = json;
/*
This line is optional, it replaces escaped brackets with real ones,
i.e. < is replaced with < and > is replaced with >
*/
strInputCode = strInputCode.replace(/( )*/g,"");
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
// strTagStrippedText = '"';
strTagStrippedText = strInputCode.replace(/<'/?[^>]+(>|$)/g, "");
strTagStrippedText = $.trim(strTagStrippedText); // overbodige spaties weghalen
//strTagStrippedText += '"';
}};
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write(strTagStrippedText);
readFile();
// contents of file now 'some sample text'
// writer.truncate(11);
// contents of file now 'some sample'
// writer.seek(4);
// contents of file still 'some sample' but file pointer is after the 'e' in 'some'
//writer.write(" different text");
// contents of file now 'some different text'
}
// Einde FILE WRITER
function fail(error) {
console.log(error.code);
}
在另一个项目中,我做了完全相同的事情,但它不起作用,我创建了另一个工程,因为我需要重新开始。我是这样做的:
$(".startNew").live("click", function(){
writeFile();
$.mobile.changePage($("#games"));
krijgSpellen();
});
function writeFile(){
navigator.notification.alert("write file");
$.get("http://www.bartdekimpe.be/anoire/index.php/admin/getGamesUserJson/34", function(result){
json = result;
removeHTMLTags();
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
});
}
function removeHTMLTags(){
if(json){
var strInputCode = json;
/*
This line is optional, it replaces escaped brackets with real ones,
i.e. < is replaced with < and > is replaced with >
*/
strInputCode = strInputCode.replace(/( )*/g,"");
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
// strTagStrippedText = '"';
strTagStrippedText = strInputCode.replace(/<'/?[^>]+(>|$)/g, "");
strTagStrippedText = $.trim(strTagStrippedText); // overbodige spaties weghalen
//strTagStrippedText += '"';
}};
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write(strTagStrippedText);
readFile();
// contents of file now 'some sample text'
// writer.truncate(11);
// contents of file now 'some sample'
// writer.seek(4);
// contents of file still 'some sample' but file pointer is after the 'e' in 'some'
//writer.write(" different text");
// contents of file now 'some different text'
}
// Einde FILE WRITER
function fail(error) {
console.log(error.code);
}
它不会写文件,真的很奇怪,当我这样做时:
$(".startNew").live("click", function(){
writeFile();
$.mobile.changePage($("#games"));
krijgSpellen();
});
它不写文件,但当我这样做时:
$(".startNew").live("click", function(){
writeFile();
});
它确实起作用,并写入一个文件
从您上面的评论来看,您似乎正在动态生成与类.startNew
的链接,这就是为什么它与live
一起工作,如果您使用的是jquery 1.7+使用on
,或者使用delegate
因为live被弃用
$(function(){
$(document).on("click",".startNew", function(){ writeFile(); });
});
或代表
$(function(){
$(document).delegate(".startNew","click", function(){ writeFile(); });
});
相关文章:
- 我可以在json对象中添加一个函数吗
- 我可以限制我添加到数组中的项目数量吗
- 我可以按索引而不是名称引用ngRepeat中的项目吗
- 我可以在用于桌面AIR应用程序的Adobe Flex项目中使用JavaScript库,例如turn.js
- 在 Angular 项目中迭代 JSON 响应以创建新的 $scope obj 我可以在应用程序中使用的
- 我可以/应该根据下拉菜单栏的项目数量为其设置动态高度
- 我可以'我不能让这个JFidddle代码在我的项目中工作
- 我可以在javascript脚本方法中获得中继器项目计数吗
- 在一个项目中,我可以写一个文件,但在另一个项目我可以't、 真的很奇怪
- 当我选择项目时,可以更改组合框验证
- 我可以在另一个项目中调用javascript函数吗
- 我可以在web项目上使用binding.js进行数据绑定吗
- 是否有< light >标记,我可以用它们来存储项目的服务器端Id
- 我可以添加项目下拉列表只有当我点击它(onclick事件)
- 我可以在github页面上托管我的React/redux(客户端和api服务器)项目吗?
- jQuery类选择器-我可以瞄准两个项目
- 如何创建我可以包含的npm包,并在父项目中运行该包
- 我可以'我在springmvc项目中没有datetimepicker
- jQuery - 我可以测试项目是否被隐藏或显示吗?
- 下拉列表中有很多项目,我可以与多个淹没共享这个列表吗?