javascript Textarea selection
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;
}
77LW NO topic_id
AD
Další témata ....(Topics)
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
Eclipse IDE Prevent debuger to break at first line of file
Project > Properties > PHP > Debug", unselect "Break at First Line"
or
Windows -> Preferences -> PHP -> Debug" and uncheck "Break at first line".
or
Run > Debug Configurations > PHP Web Application" and unselect "Break at first line" in all the configurations.
Restart Eclipse
Date: 09.06.2020 - 20:23
Příklad vychází z předpokladu, že těsně před konečným
tagem /BODY je kontejner tag s názvem < footer>< /footer>.
Mezeru < TAGNAME nutno odstranit v reálném kódu.
Pokud tento tag je nalezen, lze předpokládat, že uživatel
stránku již uvidí celou, protože většina prohlížečů si s
tím poradí a doplní chybějící uzavírací tagy BODY a HTML.
// < TAGNAME remove space after < !!!!!
< BODY onload="myFunction">
< sript>
function myFunction() {
var x = document.getElementsByTagName ("footer");
if(x.length === 0)
alert("Page not loaded correctly ... not find tag footer x" + x);
else
alert("Heureka! :) FOOTER is loaded!");
}
< /script>
Pokud vytvářite novou instanci nějakého objektu, musíte použít klíčové slovo new
class myClass {
private $var = 'Who I am? ';
function __construct($val){
$this->var .= $val;
}
function fc()
{
print 'Hello from myClass <br>';
print $this->var;
}
}
$myInstance = new myClass('I am a variable');
$myInstance->fc(); // Hello from myClass <br>Who I am? I am a variable
Jak zjistit v javascriptu zda objekt existuje
How test if an object exists undefined or null.
if (typeof OBJECT_NAME != "undefined") {
//object exists ... execute code here.
}
// or best of use try catch
var nObject;
try{
nObject = image.image; // is image.image object?
}catch (e){
alert(e.message.toString()); // e.message == 'undefined' is null or not an object
return; // or continue if image.image is a object
}
// you can test now nObject as typeof nObject
if(typeof nObject == 'string') // or others etc.
{
// do something
}
// dont use this
if (OBJECT_NAME != null) {
//if object dont exists will error
}
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:javascript-textarea-selection