Add floating button and click scroll to the bottom of the page to demonstrate the code IE9, 11, Maxthon 1.6.7, Firefox30, 31,360, and firefox30.
To add a floating button to the webpage over the past two days, click this button to scroll to the bottom of the webpage. I searched through bing on the Internet. Most of them are JQuery.
I want JavaScript only, so I have to DIY it. The test is normal in IE9, 11, Maxthon 1.6.7, Firefox30, and 31,360 speed browsers 7.5.3.308.
The difficulty lies in the setScrollBottom function.
In general:
function setScrollBottom(value) {if (document.documentElement.scrollTop){ document.documentElement.scrollTop += value;} else {document.body.scrollTop += value;}}
Click the floating button when the page is loaded for the first time. It will be invalid in IE9, 11, Maxthon 1.6.7, Firefox30, and 31, and valid in 360.
In IE9 and 11, Maxthon has umentElement. scrollTop + = value; will not be executed, while document. body. although scrollTop + = value is executed, the document. body. scrollTop is always 0.
It is valid in the extremely fast browser because it indicates the document, and the chromekernel still does not recognize document.doc umentElement. scrollTop, and only uses document. body. scrollTop.
If changed:
function setScrollBottom(value) {if (document.body.scrollTop){ document.body.scrollTop += value;} else { document.documentElement.scrollTop+= value;}}
The effect will be reversed.
To make the best of both worlds, we can add code that identifies the browser type to differentiate and handle it accordingly, but we can use document. body. whether the scrollTop value is always 0 is a simple distinction, as shown in the following DEMO code.
Btw: find two simple code on the Internet:
Its 1:
<A href = "#1" onclick = "window. scrollTo (); return false;"> method 1 at the bottom of the webpage </a>
Idea: document. all [document. all. length-1] gets the last element. ScrollIntoView () scroll to the line of sight. Both IE and FireFox are supported. It is not applicable when the last element of the document is not at the bottom.
Its 2:
<A href = "#1" onclick = "window. scrollTo (); return false;"> method 2 at the bottom of the webpage </a>
Idea: you only need to scroll to a far and far place.
It is also included in the Demo code.
<! DOCTYPE html>
On the webpage, select the content in the selection box and click the Add button to add the content to the right selection box. How can this problem be achieved using javascript ?? Urgent
The example below passes the test under chrome 22 IE9 firefox16
<Select size = "5" id = "select1">
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
<Option value = "5"> 5 </option>
</Select>
<Input type = "button" name = "button" id = "button" value = "Submit" onClick = "addOption ()">
<Input type = "button" name = "button" id = "button" value = "delete" onClick = "delOption ()">
<Select id = "select2" size = "5"> </select>
<Script>
Function addOption (){
Var index = select1.selectedIndex;
If (index <0 ){
Alert ("no project is selected ")
Return false
}
Var theOpt = select1.options [index]
// Obtain the currently selected Element
, Txt = theOpt. text
, Val = theOpt. value
// Obtain the text and value values
, NewOpt = new Option (txt, val)
// Create a new element
, Len = select2.options. length
// Obtain the number of all elements of the target.
Select2.options [len] = newOpt
// Assign a value to add an element
}
Function delOption (){
Var index = select2.selectedIndex;
If (index <0 ){
Alert ("the project to be deleted is not selected ")
Return false
}
Select2.remove (index)
}
</Script>... the remaining full text>