javascript-events

How to move rectangle on canvas

眉间皱痕 提交于 2019-12-21 17:22:20
问题 I use canvas in my application using JavaScript. On that canvas I draw one rectangle. I want to move rectangle with the help of mouse(e.g moving slider) how to move that rectangle using JavaScript or J-query. 回答1: A Canvas is literally just a surface that you paint on and none of the things you paint are objects. If you want to pretend they are objects (like moving around a rectangle or a line) then you need to keep track of everything and do all the hit-testing and re-painting yourself . I

Javascript fires two events - onkeypress and onclick

自古美人都是妖i 提交于 2019-12-21 15:18:12
问题 Problem is when I press a key over a radio button, element MyFunc fires twice - once for "onkeypress" event, another time for "click" event. Question "Why?" I need to handle this by two different ways, but now I can not recognize what initial event was. When I click a mouse it fires just for "click" event. <ul> <li> <input type="radio" onkeypress="MyFunc(event, this)" onclick="MyFunc(event, this)" name="myList" id="MyId_1" />Topic 1 <input type="radio" onkeypress="MyFunc(event, this)" onclick

does anyone have experienced cross browser issues with “encodeURIComponent(string)”

元气小坏坏 提交于 2019-12-21 13:40:22
问题 I need to make URL from some custom string values dynamically. I have doubt on "encodeURIComponent(string)" function whether it has cross browser issues does anyone experienced trouble with this function(I am not using any JS libraries)? 回答1: encodeURIComponent works as advertised in a cross-browser fashion. Use it in preference to escape . 回答2: Go for it. This is exactly what encodeURIComponent is for and it's well-supported across browsers. I've never heard of a serious issue with it on any

How to catch “History.Back” event in javascript?

浪尽此生 提交于 2019-12-21 09:16:35
问题 is it posible to catch "History.Back" event in javascript? İ want to catch history.back() event and logout user. P.s : There is some code about disabling history.back(). But is not useful for me. <script type = "text/javascript" > function disableBackButton() { window.history.forward(); } setTimeout("disableBackButton()", 0); </script> then set onunload event <body onunload="disableBackButton()"> 回答1: You can catch history back using "window.onpopstate" event. But AFAIK it is only available

How to catch “History.Back” event in javascript?

自闭症网瘾萝莉.ら 提交于 2019-12-21 09:16:06
问题 is it posible to catch "History.Back" event in javascript? İ want to catch history.back() event and logout user. P.s : There is some code about disabling history.back(). But is not useful for me. <script type = "text/javascript" > function disableBackButton() { window.history.forward(); } setTimeout("disableBackButton()", 0); </script> then set onunload event <body onunload="disableBackButton()"> 回答1: You can catch history back using "window.onpopstate" event. But AFAIK it is only available

attachEvent / addEventListener to Window onload / load - preferred way

情到浓时终转凉″ 提交于 2019-12-21 09:15:02
问题 I have a script that starts when the page loads and I had been using this code below to start it: if (window.addEventListener) { window.addEventListener('load', otherRelatedParts, false); } else if (window.attachEvent) { window.attachEvent('onload', otherRelatedParts ); } but today I tried with a self invoking function like this: (function() { otherRelatedParts(); }()) It seems to work, in all browsers and is less code. Is this the preferred way to add events to the window load? 回答1: Your

Difference between document.hidden vs document.hasFocus()

巧了我就是萌 提交于 2019-12-21 09:03:07
问题 Please explain the difference between document.hidden , the HTML5 Page Visibility API and document.hasFocus() . I am doing a project which pops HTML5 Desktop Notification when the tab is not focused . I am kind of confused which one to use. 回答1: The hidden attribute is defined like this: On getting, the hidden attribute MUST return true if the Document contained by the top level browsing context (root window in the browser's viewport) is not visible at all. The attribute MUST return false if

Difference between document.hidden vs document.hasFocus()

北战南征 提交于 2019-12-21 09:01:20
问题 Please explain the difference between document.hidden , the HTML5 Page Visibility API and document.hasFocus() . I am doing a project which pops HTML5 Desktop Notification when the tab is not focused . I am kind of confused which one to use. 回答1: The hidden attribute is defined like this: On getting, the hidden attribute MUST return true if the Document contained by the top level browsing context (root window in the browser's viewport) is not visible at all. The attribute MUST return false if

how can remove backslash in value by jQuery?

淺唱寂寞╮ 提交于 2019-12-21 08:26:08
问题 if $(this).val() have backslash remove backslash in it by jQuery. how is it? 1111\/11\/11 -> 1111/11/11 回答1: $(this).val().replace(/\\/g, ''); You have to use two backslashes to get the \ character. A single backslash is used for control characters such as \r \n etc. Using the double backslash escapes this and gives you what you want. 回答2: var str = $(this).val().replace('/',''); 回答3: Try this. $(this).val($(this).val().replace(/\\/gi, "")); 来源: https://stackoverflow.com/questions/6758734/how

preventDefault() doesn't work

随声附和 提交于 2019-12-21 07:11:29
问题 When I use event.preventDefault() on a link it works, however when I use it on a button doesn't! DEMO my code: <a id="link" href="http://www.google.com">link</a> <button id="button" onclick="alert('an alert')">button</button>​ $('#link').click(function(event){ event.preventDefault(); }); $('#button').click(function(event){ event.preventDefault(); }); ​ Link action is cancelled, but when I click on the button, still executes the onClick action Any help? what I want to do is to prevent the