如何将jquery代码转换为原型代码? [英] How can convert jquery code to prototype code?

查看:121
本文介绍了如何将jquery代码转换为原型代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery代码,但无法正常工作,似乎我需要原型代码.

I have a jquery code but is not working and seems that I need prototype code.

这是代码: http://jsfiddle.net/qKG5F/1627/

Here is the code: http://jsfiddle.net/qKG5F/1627/

<script type="text/javascript">
(function() {
$('form > input').keyup(function() {

    var empty = false;
    $('form > input').each(function() {
        if ($(this).val() == '') {
            empty = true;
        }
    });

    if (empty) {
        $('#search').attr('disabled', 'disabled');
    } else {
        $('#search').removeAttr('disabled');
    }
});
})()
</script>
<form>
FROM<br />
<input type="text"/><br />
TO<br />
<input type="text"/><br />     
<input type="submit" id="search" value="GO" disabled="disabled" />
</form> 

请有人可以帮我将这个jquery转换为原型代码吗?

Please somebody can help me to convert this jquery to prototype code?

将接受所有类型的帮助.

All kind of help will be accepted.

推荐答案

出于完整性考虑,我继续将您的代码转换为PrototypeJS.找到第一个空字段后,我对代码进行了一些优化(很抱歉无法解决).

For sake of completeness I went ahead and converted your code to PrototypeJS. I optimized the code a bit (sorry can't help it) to exit when the first empty field is found.

<script type="text/javascript">
document.observe('dom:loaded',function(){
    $$('form > input').invoke('observe','keyup',function() {
        var empty = false;
        $$('form > input').each(function() {
            if (this.value == '') {
                empty = true;
                throw $break;
            }
        });
        $('search').writeAttribute('disabled',empty);
    });
});
</script>
<form>
FROM<br />
<input type="text"/><br />
TO<br />
<input type="text"/><br />     
<input type="submit" id="search" value="GO" disabled="disabled" />
</form> 

这篇关于如何将jquery代码转换为原型代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆