检查textarea的元素类型,选择一个,按钮不起作用

时间:2013-01-10 13:38:31

标签: jquery vbscript

我正在将vb脚本功能转换为javascript。

If oElement.type = "text" Or oElement.type = "textarea" Or oElement.type = "checkbox" Or oElement.type = "select-one" Or oElement.type = "button" Then

我需要转换关于vbscript的行。当我使用以下解决方案时,它会为'textarea','select-one'和'button'提供一些脚本错误。这对'text'和'checkbox'工作正常。< / p>

  $("#frmOrder").children().each(function () {
    var child = $(this);
    // type checking for textarea,select-one,button is not working.
    if (child.is(":text") || child.is(":checkbox")) {
        if(Number(child.attr('tabindex')) >= nIndex) {
            child.attr('tabindex', child.attr('tabindex')+ <%=nChemIndexIncrement%>);
        }
    }
});

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您必须检查有效的css选择器,:hoverfirst-child是这些伪类的示例。 :checkbox:text不存在。请改为input[type=text]

$("#frmOrder").children().each(function () {
    var child = $(this);
console.log(child);
    // type checking for textarea,select-one,button is not working.
    if (child.is("input[type=text]") || child.is("input[type=checkbox]") || child.is("textarea") || child.is("button") || child.is("input[type=button]")) {
        if(Number(child.attr('tabindex')) >= nIndex) {
            child.attr('tabindex', child.attr('tabindex')+ nChemIndexIncrement);
        }
    }
});

看到这个工作jsfiddle:http://jsfiddle.net/GKegv/