【发布时间】:2013-01-26 19:12:28
【问题描述】:
谁能帮我将数据存储在从文本框中获取的数组中。我需要设计一种格式,以便在按下空格时它应该在空格字符之前显示不同的字体颜色。并且空格后面的元素应该和往常一样。
编辑:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
var x = 0
function abc() {
var a = new Array("a", "b", "c", "d", "e", "f", "g", ..... "h", "x", "y", "z")
document.getElementById("type").value = a[x]
var i = document.getElementById("type").value
var n = i.charAt(i.length - 1)
alert(n)
var n = i.substring(0, i.length - 1)
document.getElementById("type").value = n.concat(a[x]);
if (x >= 0) x++
if (x >= 26) x = 0
}
</script>
</head>
<body>
<!--<input type="text" name="type" id="type" size="100" onkeyup="abc()">-->
<input type="text" name="type" id="type" size="100" onkeypress="abc()">
<div id="log"></div>
另一个尝试:
<script>
e = jQuery.Event("keypress", {
keyCode: 32
});
jQuery('#type').bind('keydown', function (e) {
var s = e.which;
jQuery('#log').html(e.which);
if (s == 8) { //backspace
alert('back space');
}
if (s == 32) { //space bar
alert('space');
var z = document.getElementById("type").value
jQuery('#type').css({
'color': 'blue'
});
}
});
</script>
</body>
</html>
【问题讨论】:
-
您的问题是关于更改输入元素中的文本颜色还是将数据存储在数组中?我看不出这些有什么关系。你能澄清你的问题吗?
-
不能对输入中的部分文本设置样式,只能设置整个输入的样式。正如@gilly3 所提到的,主题说一件事,问题文本有所不同。请尽量简洁
标签: javascript jquery arrays associative-array