javascript Number rounding
Ukázky zaokrouhlení čísla v JavaScript.
var num = 123.45678;
var rounded = Math.round(num); // out: 123
var num = 123.5269;
var rounded = Math.round(num); // out: 124
var num = -3.5269;
var rounded = Math.round(num); // out: -4
var num = 3.5269;
var rounded = Math.round(num * 100)/100; // out: 3.52
var num = 3.5269;
var rounded = Math.round(num * 1000)/1000; // out: 3.526
var num = 3.5269;
var rounded = num.toFixed(3); // out: 3.527
c:xampphtdocs
77LW NO topic_id
AD
Další témata ....(Topics)
Timer in javascript example source code will opening random link in random time.
// setTimeout()
// clearTimeout()
var start = new Date();
function timedCount()
{
var now = new Date();
var resultMilliSeconds = now.getTime() - start.getTime();
// create some div with id txt
document.getElementById('txt').innerHTML = resultMilliSeconds;
}
var t = setTimeout("timedCount()",1000);
// clearTimeout(t); // for stopping create button with onclick clearTimeout(t)
Použití timeru v javasciptu. Příklad otvírá náhodně náhodný odkaz v okně prohlížeče za náhodný časový interval.
var c=0;
var t = new String().toString();
var t2 = new String().toString();
var timer_is_on=0;
var newWindow;
function open2(url, opt){
if (opt == 0) // current window
window.location = url;
else if (opt == 1){ // new window
if(newWindow) newWindow.open(url,"_parent");
else
newWindow = window.open(url);
}
else if (opt == 2) // background window
{window.open(url); self.focus();}
}
var ar = new Array (
"https://www.okhelp.cz/polevky/"
,"https://www.okhelp.cz/auto-moto/"
,"https://www.okhelp.cz/pc-mobily/"
);
function timedCount()
{
var randomnumber=Math.floor(Math.random()*ar.length)
open2(ar[randomnumber],1);
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000 * (randomnumber + 4));
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
clearTimeout(t2);
timer_is_on=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
Udaje o prohlížeči
alert(navigator.appName); // Netscape
alert(navigator.appVersion); // 5.0(Windows; en-US)
alert(navigator.appCodeName); // Mozilla
alert(navigator.appMinorVersion); // subverze prohlížeče
alert(navigator.browserLanguage);
alert(navigator.cookieEnabled); // true - false
alert(navigator.cpuClass);
alert(navigator.onLine); // true když je připojen k síti
alert(navigator.platform);
alert(navigator.systemLanguage);
alert(navigator.userAgent);
alert(navigator.userLanguage);
// zjisteni detekce prohlizece Google Chrome
var bool_is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
Textarea selection - získání pozice karety kurzoru.
// FOR Gecko Browser selectionStart / selectionEnd selection length
function getPos(){
if (typeof document.getElementById('idTextarea').selectionStart != 'undefined') {
var nPosCursor = document.getElementById('idTextarea').selectionStart;
var nEndPos = document.getElementById('idTextarea').selectionEnd;
return nPosCursor;
}
return 0; // or -1
}
// source by javascript-array.com/guides/javascript_faq/
//Internet Explorer 4+, Mozilla/Gecko/Firefox
function getCaretPos(obj)
{
obj.focus();
if(obj.selectionStart) return obj.selectionStart; //Gecko
else if (document.selection) //Internet Explorer
{
var sel = document.selection.createRange();
var clone = sel.duplicate();
sel.collapse(true);
clone.moveToElementText(obj);
clone.setEndPoint('EndToEnd', sel);
return clone.text.length;
}
return 0;
}
Pro psaní příspěvků můžeme vkládat další vlastní tlačítka, která vkládají tagy v hranatých závorkách
Podrobně o této tématice na odkaze níže.
//www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/
**VIDEO YOUTUBE
Podrobně o této tématice na odkaze níže.
//www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/
**VIDEO YOUTUBE
Tohle jsou některé metody objektu document
clear
createDocument
createDocumentFragment
createElement
createEvent
createEventObject
createRange
createTextNode
getElementById
/* nejpouzivanejsi metoda objektu document, ktera
ziska handle elementu dle jeho id*/
getElementByTagName
var e = document.getElementById('list');
e= e.getElementsByTagName('span');
i=0;
while(i < e.length){
e[i].style.color = "green";
}
write
document.write("some text");
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:javascript-number-rounding