与e.preventDefault和e.stopPropagation()相反;

时间:2017-01-20 13:42:44

标签: javascript jquery

我写了一些javascript代码,可以防止在焦点上滚动。如何在焦点丢失后禁用它?

焦点

e.preventDefault = false;
e.stopPropagatio = false;

关注

declare @sdate date
set @sdate = DateAdd(day,-1,getdate())

declare @edate date
set @edate =getdate()

SELECT  i.print_date

FROM dbo.WC_view_bill_hdr AS i
JOIN dbo.WC_view_customer AS c ON i.customer_id = c.customer_id
JOIN WC_view_bill_batch AS ib ON ib.bill_batch_uid = c.bill_batch_uid

  WHERE
 i.print_date between @sdate and @edate

2 个答案:

答案 0 :(得分:1)

您无法撤消preventDefaultstopPropagation

停止打电话给他们,例如

var stopScroll = true;
element.addEventListener('scroll', function() {
  if (stopScroll) {
    e.preventDefault();
    e.stopPropagation();
  }
});
// ...
stopScroll = false;
function listener() {
  e.preventDefault();
  e.stopPropagation();
}
element.addEventListener('scroll', listener);
// ...
element.removeEventListener('scroll', listener);

答案 1 :(得分:1)

通过解除事件绑定来解决。

焦点

$('.form-control').focusout(function() {
        $('#element').unbind();
});

关注

public class InitialActivity extends AppCompatActivity {

private static final String TAG = InitialActivity.class.getSimpleName();
private final String DATABASE_NAME = "sqlite_src.db";
private final String DATABASE_FOLDER = "/databases/";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_initial);

    getSupportActionBar().hide();


    // Just for testing... make sure AsyncTask is called

    /*
    File file = this.getDatabasePath(DATABASE_NAME);
    if(file.exists()) {

        RunMainActivity();

    }
    */

}

private void RunMainActivity() {

    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();

}

@Override
protected void onStart() {

    super.onStart();

    CopyFileFromAsset task = new CopyFileFromAsset(this);
    task.execute();

}

private class CopyFileFromAsset extends AsyncTask<Void, Integer, Boolean> {

    private Context ctx = null;

    private CopyFileFromAsset(Context c) {

        this.ctx = c;

    }


    @Override
    protected void onPostExecute(Boolean aBoolean) {

        if(aBoolean)
            RunMainActivity();

    }

    @Override
    protected Boolean doInBackground(Void... voids) {

        // Just for testing... in this case the layout is shown

        try {
            Thread.sleep(5000);
        }
        catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }

        return true;

        // When copying the file the layout is NOT shown

        /*
        File file = ctx.getDatabasePath(DATABASE_NAME);
        Log.d(TAG, "File " + file.toString());
        File folder = file.getParentFile();
        Log.d(TAG, "Folder " + folder.toString());
        if(!folder.exists()) {
            Log.d(TAG, "Folder doesn't exist");
            folder.mkdirs();
        }
        try {
            InputStream is = ctx.getAssets().open(DATABASE_NAME);
            OutputStream os = new FileOutputStream(file);
            byte[] buffer = new byte[1024];
            while (is.read(buffer) > 0) {
                os.write(buffer);
            }
            is.close();
            os.flush();
            os.close();
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }

        return file.exists();
        */

    }

}