Commit cd1ca608 authored by Jesper Zedlitz's avatar Jesper Zedlitz

Einfügen von Sonderzeichen

parent 69aa5c43
<html>
<head>
<meta charset="utf-8"/>
<title>Sonderzeichen</title>
</head>
<body>
<h1>Einfügen von Sonderzeichen</h1>
<p>Beim Klick auf einen der Buttons wird in das zuletzt fokussierte input-Element das entsprechende Zeichen eingefügt.</p>
<input name="a" id="inputA" class="insertSpecialCharacter"/>
<input name="b" id="inputB" class="insertSpecialCharacter"/>
<div style="margin-top:1em;" id="specialCharacters"></div>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script type="application/javascript" src="../src/specialCharacters.js"></script>
<script type="application/javascript">
$(document).ready(function(){
createSpecialCharacterList('ČŠŽčěłőřšżž', true);
});
</script>
</body>
</html>
var activeInput;
function createSpecialCharacterList( characters, useButtons ) {
var specialCharDiv = $('#specialCharacters');
if( specialCharDiv.length ) {
for (var i = 0, len = characters.length; i < len; i++) {
var c = characters[i];
if( useButtons ) {
specialCharDiv.append("<button onClick=\"insertChar('"+c+"');\">"+c+"</button> ");
} else {
specialCharDiv.append("<a href=\"#\" onClick=\"insertChar('"+c+"');\">"+c+"</a> ");
}
}
} else {
console.log("Um die Zeile zum Einfügen der Spezialzeichen zu verwenden, muss es ein Element mit der id 'specialCharacters' geben.");
}
$("input").focusin(function() {
// console.log("focus: "+$(this));
activeInput = $(this);
});
}
function insertChar( c ) {
if(activeInput) {
activeInput.val(activeInput.val()+c);
activeInput.focus();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment