dhtml

Determine which element submitted a form from within onsubmit

孤街浪徒 提交于 2019-11-28 03:33:34
问题 Is there a way to determine which element submitted a form from within an onsubmit handler? Trying to write a generic handler that knows which element was clicked. For example, given this form: <form onsubmit="onSubmitHandler"> <input type="submit" name="submit1" /> <input type="submit" name="submit2" /> </form> How can I determine inside the onSubmitHandler which submit button was clicked? I tried event.target/event.srcElement, but that gives the form, not the actual submit button. Update: I

ScrollTop not working in IE

↘锁芯ラ 提交于 2019-11-28 03:08:35
问题 Anyone have any ideas why scrollTop isn't working in IE? It works in Chrome fine, and I don't know about firefox. (The idea of this script is to have an autoscrolling page that resets once it hits the bottom of the page) function getheight() { var myWidth = 0, myHeight = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement

window opener close issue for javascript

有些话、适合烂在心里 提交于 2019-11-27 19:39:06
问题 I have a problem with browsers window managament with javascript. I have two page in my proof of concept application. First page contains login information (username, password, login button etc.) and second page is a managament screen. I need that when the user pressed to the login button on the login screen it open to main screen and main screen must be open new window without full screen. I mean close, minimize, maximize buttons and bottom bar of the windows os must be stayed on the screen.

Set content of HTML <span> with Javascript

拈花ヽ惹草 提交于 2019-11-27 19:14:04
In a webpage I am calling a WebService that gives me an integer value. I need to display this value in a block of text. I am currently using an HTML <span> . So far, I've found two methods of putting my value in a span. innerText() is an IE proprietary way of doing it and innerHTML() is a non-standards compliant way, although widely supported. What is the correct standards compliant way of setting the text between <span> and </span> from Javascript? This is standards compliant and cross-browser safe. Example: http://jsfiddle.net/kv9pw/ var span = document.getElementById('someID'); while( span

Deep cloning vs setting of innerHTML: what's faster?

女生的网名这么多〃 提交于 2019-11-27 18:46:16
I'm trying to figure out the most performant way of deep-cloning a DOM tree within the browser. If I start out with var div = document.getElementById("source"); var markup = div.innerHTML; What will be faster, var target = div.cloneNode(true); or var target = document.cloneNode(false); target.innerHTML = markup; I understand the browser platform may make a big difference here, so any information about how these compare in the real world would be appreciated. Let's test! I added the following code to a copy of StackOverflow's Questions page (removing existing scripts first, and running from

html - selection range - getting the range + starting node + ending node + distance

爷,独闯天下 提交于 2019-11-27 18:05:08
问题 From my previous question for selecting specific html text, I have gone through this link to understand range in html string. For selecting a specific text on html page. We need to follow this steps. Assumed HTML: <h4 id="entry1196"><a href="http://radar.oreilly.com/archives/2007/03/call_for_a_blog_1.html" class="external">Call for a Blogger's Code of Conduct</a></h4> <p>Tim O'Reilly calls for a Blogger Code of Conduct. His proposals are:</p> <ol> <li>Take responsibility not just for your own

jQuery and appending large amounts of HTML

孤者浪人 提交于 2019-11-27 16:41:24
问题 I have come to find that using jQuery to create HTML client-side can be a huge performance booster if done properly. I use AJAX returning JSON to retrieve dynamic content and then I build the relevant HTML and insert it using jQuery. The first time I messed with this technique I found that the string concatenator in IE's JavaScript performed really slowly so that building a dynamic table with more than 50 or so rows performed terribly. var shtml = '<table>'; for (var i = 0; i < 100; i++) {

Boolean HTML Attributes

爷,独闯天下 提交于 2019-11-27 08:22:45
There are some attributes in HTML which are "boolean" - browsers treat them as "true" if they are present, regardless of the value. An example of such an attribute is selected on the <option> tag. Another is checked on <input type="checkbox"> . If you have a call to setAttribute() for such an attribute, there seems to be no value you can set to have the browsers consistently behave as though the attribute is missing. For example option.setAttribute("selected", false) will still mark the option selected. null , empty string or undefined don't work either. If anyone knows of a value I can set to

decodeURIComponent vs unescape, what is wrong with unescape?

纵饮孤独 提交于 2019-11-27 06:43:55
In answering another question I became aware that my Javascript/DOM knowledge had become a bit out of date in that I am still using escape / unescape to encode the contents of URL components whereas it appears I should now be using encodeURIComponent / decodeURIComponent instead. What I want to know is what is wrong with escape / unescape ? There are some vague suggestions that there is some sort of problem around Unicode characters, but I can't find any definite explanation. My web experience is fairly biased, almost all of it has been writing big Intranet apps tied to Internet Explorer. That

Modifying a query string without reloading the page

孤街浪徒 提交于 2019-11-27 06:20:14
I am creating a photo gallery, and would like to be able to change the query string and title when the photos are browsed. The behavior I am looking for is often seen with some implementations of continuous/infinite page, where while you scroll down the query string keeps incrementing the page number ( http://x.com?page=4 ) etc.. This should be simple in theory, but I would like something that is safe across major browsers. I found this great post , and was trying to follow the example with window.history.pushstate , but that doesn't seem to be working for me. And I'm not sure if it is ideal