我想用localStorage将数据保存在用户的手机上.我的应用程序是使用phonegap构建的.
function check_connection()
{
var id = window.localStorage.getItem("id");
if(id != null)
// some code
console.log(id);
}
Run Code Online (Sandbox Code Playgroud)
当我执行此代码后window.localStorage.setItem("id", "value");,我得到"值",但如果我退出应用程序并再次运行它,我得到"null".
document.addEventListener("deviceready", main, true);
function main()
{
check_connection();
}
Run Code Online (Sandbox Code Playgroud)
出口似乎清除了localStorage对象.
任何的想法 ?
编辑:当我通过按后退按钮退出应用程序时数据是持久的,但是当我从最近的应用程序中删除应用程序时,数据被清除.问题是什么 ?
我正在尝试在我的网站上添加CKEDITOR 4.2(使用Chrome 29和Firefox 23测试),ckeditor.js在head部分中加载,textarea加载到ajax中,然后替换为:
CKEDITOR.replace('editor');
Run Code Online (Sandbox Code Playgroud)
但之后我无法在文本字段中写入,当我单击任何按钮时,会出现错误 Cannot call method 'getSelection' of undefined
CKEDITOR.dom.selection = function (a) {
var b = a instanceof CKEDITOR.dom.element;
this.document = a instanceof CKEDITOR.dom.document ? a : a.getDocument();
this.root = a = b ? a : this.document.getBody();
this.isLocked = 0;
this._ = {
cache: {}
};
b = o ? this.document.$.selection : this.document.getWindow().$.getSelection(); // Error
// ...
}
Run Code Online (Sandbox Code Playgroud)
它正在一个空页面上工作,没有ajax但不在网站上,可能是与其他脚本冲突?
任何的想法 ?
我将沉浸式模式添加到我的应用程序中。这是代码:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus)
{
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我在键盘上打字并关闭它(使用“后退”按钮,通过单击屏幕),导航栏保持显示状态,则需要缩小/重新打开该应用程序才能返回沉浸式模式。
关闭键盘后如何返回沉浸式模式?
编辑:这是一个Cordova应用程序
我想在设备上获取原生屏幕宽度以在DOM中附加脚本.是否可以使用jQuery?
谢谢
是否可以使用mousemove获取当前元素?如果鼠标不在元素x或y上,我想获取鼠标所在的元素.
举个例子 :
$(document).mousemove(function(e)
{
if(e.xxxx.attr("id") == "elem")
...
});
Run Code Online (Sandbox Code Playgroud)
xxxx是我正在寻找的,我希望它存在:)
谢谢
我试图从javascript中的日期获取时间戳,但new Date(2013, 03, 17).getTime()返回1366149600000错误(1981-2-2 23:11:12).如果我删除最后三个零,我会得到好日期.
问题来自哪里?
我已经在RelativeLayout中创建了一个Button,我想设置它的大小.但我只能设置一个比原来更大的尺寸,例如我可以将其调整为200dp但不调整为20dp.
有解决方案吗?
这是我的代码
Button b = new Button(getApplicationContext());
myLayout.addView(b);
b.setWidth(200); // Work
b.setWidth(20); // Don't work
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试使用tomcat保护我的管理页面web.xml,tomcat-users.xml但它不起作用.登录表单出现但无法连接
这是web.xml在我的web/WEB_INF文件夹中:
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Admin</realm-name>
</login-config>
Run Code Online (Sandbox Code Playgroud)
而tomcat-users.xml在服务器/ tomcat的/ conf目录/文件夹:
<tomcat-users>
<role rolename="manager"/>
<role rolename="tomcat"/>
<role rolename="admin"/>
<role rolename="role1"/>
<user username="manager" password="manager" roles="manager"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="admin" password="admin" roles="admin"/>
</tomcat-users>
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?
我不知道如何安装CKeditor,我在网站上下载了编辑器,然后将以下代码放在我的head标签之间:
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor1 = new CKEDITOR('message');
oFCKeditor1.ToolbarSet = 'Basic' ;
oFCKeditor1.BasePath = "ckeditor/" ;
oFCKeditor1.ReplaceTextarea() ;
}
</script>
Run Code Online (Sandbox Code Playgroud)
但是下面的行返回了我的错误:
未捕获的TypeError:对象不是函数
var oFCKeditor1 = new CKEDITOR('message');
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?
我正在尝试fragments在ViewPager下面的按钮单击中动态添加/删除,但如果我remove通过单击后退按钮获取片段(表单),并再次添加片段,则表单保留其数据(EditText不为空).
这是我的适配器:
package com.thomas.playlists.viewPager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
public class ViewPagerAdapter extends FragmentPagerAdapter
{
ArrayList<Fragment> mList = null;
public ViewPagerAdapter(FragmentManager fm)
{
super(fm);
mList = new ArrayList<Fragment>();
}
public void add(Fragment fragment)
{
mList.add(fragment);
}
public void removeLast()
{
if(mList.size() > 1)
mList.remove(getCount() - 1);
}
@Override
public Fragment getItem(int i)
{
return mList.get(i);
}
@Override
public int getCount()
{
return mList.size();
}
}
Run Code Online (Sandbox Code Playgroud)
添加proccess两次使用(在主Activity中):
PlaylistFragment playlistFragment = new PlaylistFragment(); …Run Code Online (Sandbox Code Playgroud) android android-arrayadapter android-fragments android-viewpager
我试图在我的环境中使用不同的缓存系统.我想有,例如,Filesystem用于开发和memcached进行督促.
我正在使用symfony 3.3.10.
为实现这一目标,我想将CacheInterface自动装配如下:
use Psr\SimpleCache\CacheInterface;
class Api {
public function __construct(CacheInterface $cache)
{
$this->cache = $cache;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的配置文件:
config_dev.yml:
framework:
cache:
app: cache.adapter.filesystem
Run Code Online (Sandbox Code Playgroud)
config_prod.yml:
framework:
cache:
app: cache.adapter.memcached
...
Run Code Online (Sandbox Code Playgroud)
将FilesystemCache声明为服务时,错误消失:
services:
Symfony\Component\Cache\Simple\FilesystemCache: ~
Run Code Online (Sandbox Code Playgroud)
但是现在我不能为NullCache这样的测试环境建立另一个缓存系统.实际上,我只需要声明一个继承自CacheInterface的服务.这是不可能config_test使用config_dev了.
这是services.yml的开始,如果它可以帮助:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Run Code Online (Sandbox Code Playgroud)
有关如何根据环境自动装配不同缓存系统的任何想法?
这是工作配置:
use Psr\Cache\CacheItemPoolInterface;
class …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Echo示例在Android上为Cordova 3.0创建插件,但它无法正常工作.
我加入<plugin name="MMSSender" value="my.package.mms.MMSSender" />了我config.xml(来自www和做过cordova build)
然后我my.package.mms用给出的示例代码创建了一个新的MMSSender类;
package my.package.mms;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Echo extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("echo")) {
String message = args.getString(0);
this.echo(message, callbackContext);
return true;
}
return false;
}
private void echo(String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message); …Run Code Online (Sandbox Code Playgroud) 我想用Javascript做一些继承.问题是我不知道如何在继承的对象上保留A类原型.
这是我的代码:
function Base() {
this.attribute1 = null;
}
Base.prototype = {
baseFunction: function() {}
};
function SubBase()
{
Base.call(this); // Constructor call
this.baseFunction();
this.subBaseFunction();
}
SubBase.prototype = Base.prototype;
SubBase.prototype = {
subBaseFunction: function() {},
subBaseOtherFunction: function() {}
}
Run Code Online (Sandbox Code Playgroud)
通过这种方式我擦除Base.prototype但我不想.
我试过SubBase.prototype.__proto__ = Base.prototype;但显然太慢了.
我知道我可以做(但是写的时间太长而对我来说不是那么干净):
SubBase.prototype.subBaseFunction = function() {};
SubBase.prototype.subBaseOtherFunction = function() {};
Run Code Online (Sandbox Code Playgroud)
我该怎么做/写得更好?
android ×5
javascript ×3
ckeditor ×2
cordova ×2
jquery ×2
admin ×1
ajax ×1
autowired ×1
button ×1
caching ×1
config ×1
date ×1
inheritance ×1
keyboard ×1
login ×1
mobile ×1
mousemove ×1
object ×1
oop ×1
php ×1
plugins ×1
prototype ×1
psr-6 ×1
size ×1
symfony ×1
timestamp ×1
tomcat ×1
view ×1
width ×1