admin管理员组文章数量:1336603
I want to know alternative for .keyup
function. Example
$(".color").keyup(function () {
var top_header = $("#top_header").val();
$("#top").css("background-color", top_header);
});
<input value="#121212" class="color" id="top_header" type="text" />
This code will change id='top'
with a new background when we type to the input text.
Now I change it to jscolor to the field. So when we click to the text input will shown color generator.
Question
What should I replace .keyup(function ()
to make make color change instantly without to have enter?
Example without using jscolor /
I want to know alternative for .keyup
function. Example
$(".color").keyup(function () {
var top_header = $("#top_header").val();
$("#top").css("background-color", top_header);
});
<input value="#121212" class="color" id="top_header" type="text" />
This code will change id='top'
with a new background when we type to the input text.
Now I change it to jscolor to the field. So when we click to the text input will shown color generator.
Question
What should I replace .keyup(function ()
to make make color change instantly without to have enter?
Example without using jscolor http://jsfiddle/5dsXT/
Share Improve this question edited Mar 2, 2011 at 16:09 Šime Vidas 186k65 gold badges288 silver badges391 bronze badges asked Mar 2, 2011 at 16:00 Unknown ErrorUnknown Error 7976 gold badges14 silver badges25 bronze badges 3- Color already changes intantly in the jscolor website doesnt it? jscolor. – amosrivera Commented Mar 2, 2011 at 16:12
- When I look at jscolor it seems to change colour as you type just as your jsfiddle example does. Could you clarify what you are trying to do a bit more? Perhaps an example of what isn't working might help... – Chris Commented Mar 2, 2011 at 16:14
-
yes.. actually on div
id='top'
– Unknown Error Commented Mar 2, 2011 at 16:15
2 Answers
Reset to default 4You're looking for the onChange
event try replacing the .keyup()
function with .change()
.
Example
$(document).ready(function () {
$(".color").change(function () {
var top_header = $("#top_header").val();
$("#top").css("background-color", top_header);
});
});
<input value="#121212" class="color" id="top_header" type="text" />
Edit You can see an example of them using the event on their "tweaking" page.
I'm not exactly sure what you're asking, but if you want to bind two events to that texbox you can try this:
$(document).ready(function () {
$("#top_header").bind("keyup focus", function() {
$("#top").css("background-color", $(this).val());
});
});
http://jsfiddle/5dsXT/2/
If you want to handle initial page load, focus, and keyup you can do this:
$(document).ready(function () {
SetColor();
$("#top_header").bind("keyup focus", SetColor);
function SetColor()
{
$("#top").css("background-color", $("#top_header").val());
}
});
http://jsfiddle/5dsXT/1/
本文标签: javascriptjQuery an alternative to keyup functionStack Overflow
版权声明:本文标题:javascript - jQuery an alternative to .keyup function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742410367a2469664.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论