获取table里所有的input标签,根据是否有自定义属性获取input标签的值

该代码示例展示了如何使用jQuery从HTML表单中查找带有data-isRequired属性的input元素,并打印其值。它遍历表格中的所有input字段,检查是否包含自定义属性,如果找到则输出相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="./jquery.min.js"></script>
<script>
    function show() {
        var Inputs = $('#extable').find("input"); //找到id是extable下所有的input标签  是jquery对象
        console.log(Inputs.length);
        for (var i = 0; i < Inputs.length; i++) {  //遍历input标签    
            var ishas = Inputs[i].getAttribute('data-isRequired');  //拿到input标签里面的自定义属性

            console.log(ishas);
            if (ishas == "true") {   //比对是不是有自定义属性的那个input标签
                console.log("第" + i + "有");    
                var textValue = $(Inputs[i]).val().trim();     //jQuery对象[i] 就变成了dom对象,需要通过$(dom)转为jquery对象  使用val方法获取input输入的值
                console.log(textValue);
            }
        }

    }


</script>

<body>
    <form action="https://www.baidu.com" method="GET">
        <tr id="extendFieldTr">
            <td><span class="titlenamespan">扩展字段</span></td>
            <td colspan=2>
                <table id="extable" border=0 cellpadding=0 cellspacing=2 style="margin-left:-2px">
                    <tr>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="会议日期">会议日期</div>
                        </td>
                        <td width=171 style='width:171px' nowrap>
                            <input type=text readonly name='mettingdate' class='input_css' style='width:170px;' value=''
                                onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                        </td>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="开始时间">开始时间</div>
                        </td>
                        <td width=171 nowrap>
                            <input type=text readonly name='mettingsdate' class='input_css' style='width:170px;'
                                value='' onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                        </td>
                    </tr>
                    <tr>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="结束时间">结束时间</div>
                        </td>
                        <td width=171 style='width:171px' nowrap>
                            <input type=text readonly name='mettingedate' class='input_css' style='width:170px;'
                                value='' onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                        </td>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="名称">
                                <font color="ff6600">*</font>名称
                            </div>
                        </td>
                        <td width=171 nowrap>
                            <input type=text name='nameinfo' class='input_css' style='width:170px;' value=''
                                maxlength='200' data-isRequired="true">
                        </td>
                    </tr>
                    <tr>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="主讲人">主讲人</div>
                        </td>
                        <td width=171 style='width:171px' nowrap>
                            <input type=text name='zcr' class='input_css' data-isRequired="true" style='width:170px;' value=''>
                        </td>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="对象">对象</div>
                        </td>
                        <td width=171 nowrap>
                            <input type=text name='dx' class='input_css' style='width:170px;' value=''>
                        </td>
                    </tr>
                    <tr>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="地点">地点</div>
                        </td>
                        <td width=171 style='width:171px' nowrap>
                            <input type=text name='localinfo' class='input_css' style='width:170px;' value=''>
                        </td>
                        <td class=listCaption nowrap>
                            <div class='ueexftdtitle' title="备注">备注</div>
                        </td>
                        <td width=171 nowrap>
                            <input type=text name='bz' class='input_css' style='width:170px;' value=''>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </form>
    <input type="button" onclick="show()">提交


</body>

</html>

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java-请多指教

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值