cross-browser

Inserting text at cursor in a textarea, with Javascript

﹥>﹥吖頭↗ 提交于 2019-12-17 06:16:06
问题 I've had a look round the web for solutions, and there are some, but they all seem to split code into supporting IE and Firefox. I was wondering if there's a more elegant way which would work on every browser, to insert some text at the cursor in a textarea. Thanks very much, Rich 回答1: No, there isn't. IE has its TextRange objects to do the job. IE >= 9 and everything else for the last long time has selectionStart and selectionEnd properties on textareas and text inputs. This particular task

Cross-browser (IE8-) getComputedStyle with Javascript?

核能气质少年 提交于 2019-12-17 06:09:07
问题 Since IE8 does not support getComputedStyle , we can only use currentStyle . However, it does not return the real "computed" value for some properties. For example: <style type="text/css"> #div {/* no properties are defined here */} </style> <div id="div">div</div> // returns "medium" instead of 0px document.getElementById('div').currentStyle.borderLeftWidth // returns "auto" instead of 0px document.getElementById('div').currentStyle.marginLeft // returns "undefined" instead of 1 document

complete styles for cross browser CSS zoom

六月ゝ 毕业季﹏ 提交于 2019-12-17 05:45:10
问题 I am finding it hard to get fully cross browser CSS zoom properties ..what I've is only these zoom: 2; -moz-transform: scale(2); 回答1: These will be sufficient for cross browser... Demo Note: As @martin pointed out that this may not work as intended , doesn't mean this fails, Chrome just makes it 2x larger than other browsers, because it RESPECTS zoom property as well. So it makes it 2x larger... zoom: 2; /* IE */ -moz-transform: scale(2); /* Firefox */ -moz-transform-origin: 0 0; -o-transform

How to detect input type=file “change” for the same file?

痴心易碎 提交于 2019-12-17 04:48:38
问题 I want to fire an event when the user select a file. Doing so with .change event it works if the user changes the file every time. But I want to fire the event if the user select the same file again. User select file A.jpg (event fires) User select file B.jpg (event fires) User select file B.jpg (event doesn't fire, I want it to fire) How can I do it? 回答1: You can trick it. Remove the file element and add it in the same place on change event. It will erase the file path making it changeable

Setting a width and height on an A tag

岁酱吖の 提交于 2019-12-17 04:47:37
问题 Is it possible to set the width and height in pixels on an anchor tag? I'd like to have the anchor tag to have a background image while retaining the text inside the anchor. li { width: 32px; height: 32px; background-color: orange; } li a { width: 32px; height: 32px; background-color: red; } <li><a href="#">Something</a></li> 回答1: You need to make your anchor display: block or display: inline-block; and then it will accept the width and height values. 回答2: You can also use display: inline

How to detect input type=file “change” for the same file?

断了今生、忘了曾经 提交于 2019-12-17 04:47:24
问题 I want to fire an event when the user select a file. Doing so with .change event it works if the user changes the file every time. But I want to fire the event if the user select the same file again. User select file A.jpg (event fires) User select file B.jpg (event fires) User select file B.jpg (event doesn't fire, I want it to fire) How can I do it? 回答1: You can trick it. Remove the file element and add it in the same place on change event. It will erase the file path making it changeable

Setting a width and height on an A tag

我怕爱的太早我们不能终老 提交于 2019-12-17 04:47:16
问题 Is it possible to set the width and height in pixels on an anchor tag? I'd like to have the anchor tag to have a background image while retaining the text inside the anchor. li { width: 32px; height: 32px; background-color: orange; } li a { width: 32px; height: 32px; background-color: red; } <li><a href="#">Something</a></li> 回答1: You need to make your anchor display: block or display: inline-block; and then it will accept the width and height values. 回答2: You can also use display: inline

How can I make event.srcElement work in Firefox and what does it mean?

萝らか妹 提交于 2019-12-17 04:29:17
问题 there is an if statement on my company's website that makes one web page imcompatible with firefox if(event.srcElement.getAttribute("onclick") == null){ ...code.. document.mainForm.submit(); } I've commented out the if statement conditions and now its working with forefox. My question is, what is event.srcElement.getAttribute("onclick"), is it important, would it cause problems in the future. also, is there something similar i can replace the condition with so that it works on firefox? Edit:

How can I make event.srcElement work in Firefox and what does it mean?

耗尽温柔 提交于 2019-12-17 04:28:09
问题 there is an if statement on my company's website that makes one web page imcompatible with firefox if(event.srcElement.getAttribute("onclick") == null){ ...code.. document.mainForm.submit(); } I've commented out the if statement conditions and now its working with forefox. My question is, what is event.srcElement.getAttribute("onclick"), is it important, would it cause problems in the future. also, is there something similar i can replace the condition with so that it works on firefox? Edit:

Math.round(num) vs num.toFixed(0) and browser inconsistencies

拜拜、爱过 提交于 2019-12-17 04:27:36
问题 Consider the following code: for (var i=0;i<3;i++){ var num = i + 0.50; var output = num + " " + Math.round(num) + " " + num.toFixed(0); alert(output); } In Opera 9.63 I get: 0.5 1 0 1.5 2 2 2.5 3 2 In FF 3.03 I get: 0.5 1 1 1.5 2 2 2.5 3 3 In IE 7 I get: 0.5 1 0 1.5 2 2 2.5 3 3 Note the bolded results. Why are this inconsistencies present? Does this mean that toFixed(0) should be avoided? What's the correct way to round a number to the nearest integer? 回答1: Edit: To answer your edit, use