jQuery 如果<input id="type" name="type" value="#(obj.type)" type="hidden"> 如果type=2,则隐藏输入框 和标签<td> <label class="control-label">SN:</label></td> <td><input name="sn" id="sn" class="form-control" placeholder="" type="text"> </td>
时间: 2023-07-02 13:04:21 浏览: 60
你可以使用以下 jQuery 代码来实现:
```javascript
if ($("#type").val() == "2") { // 判断 type 是否为 2
// 隐藏输入框和标签
$("label[for='sn'], #sn").hide();
}
```
这段代码首先判断 `#type` 的值是否为 2,如果是,就使用 `hide()` 方法隐藏 `label` 和 `input` 元素。其中,`label[for='sn']` 表示 `for` 属性值为 `sn` 的 `label` 元素,`#sn` 表示 `id` 为 `sn` 的 `input` 元素。
相关问题
<input name="WtSandDensityMaxDryDensityMethod1" value="@obj.WtSandDensityMaxDryDensityMethod1" type="text" class="form-control" required>如何设置默认值
在HTML中,可以使用value属性来设置<input>元素的默认值。该属性的值将作为默认文本显示在输入框中。你可以将你想要的默认值放在value属性中,例如:
```
<input name="WtSandDensityMaxDryDensityMethod1" value="默认值" type="text" class="form-control" required>
```
在上述代码中,"默认值"将作为输入框的默认值。如果用户没有输入任何内容,则将使用该默认值。同时,required属性将确保用户必须输入某个值才能提交表单。
用python帮我把下面标签中的有效数据提取出来<annotation> <folder>converted/CMS/2D目标检测/filter</folder> <filename>converted/CMS/2D目标检测/filter_empty_target_img_after_hash2/0/20230401180910649_61.jpg</filename> <source> <database>Unknown</database> <annotation>Unknown</annotation> <image>Unknown</image> </source> <size> <width>1920</width> <height>1536</height> <depth></depth> </size> <segmented>0</segmented> <object> <name>二轮车</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>626.38</xmin> <ymin>808.12</ymin> <xmax>650.03</xmax> <ymax>852.04</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>6</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> <object> <name>行人</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>1612.74</xmin> <ymin>831.51</ymin> <xmax>1627.34</xmax> <ymax>873.8</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>8</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> <object> <name>行人</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>1469.0</xmin> <ymin>832.96</ymin> <xmax>1489.43</xmax> <ymax>865.8</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>9</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> </annotation>
你可以使用Python中的xml.etree.ElementTree库来解析XML数据并提取标签中的有效数据。以下是一个示例代码,演示如何提取出有效数据:
```python
import xml.etree.ElementTree as ET
# 定义XML字符串
xml_string = '''
<annotation>
<folder>converted/CMS/2D目标检测/filter</folder>
<filename>converted/CMS/2D目标检测/filter_empty_target_img_after_hash2/0/20230401180910649_61.jpg</filename>
<source>
<database>Unknown</database>
<annotation>Unknown</annotation>
<image>Unknown</image>
</source>
<size>
<width>1920</width>
<height>1536</height>
<depth></depth>
</size>
<segmented>0</segmented>
<object>
<name>二轮车</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>626.38</xmin>
<ymin>808.12</ymin>
<xmax>650.03</xmax>
<ymax>852.04</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
<attribute>
<name>track_id</name>
<value>6</value>
</attribute>
<attribute>
<name>keyframe</name>
<value>True</value>
</attribute>
</attributes>
</object>
<object>
<name>行人</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1612.74</xmin>
<ymin>831.51</ymin>
<xmax>1627.34</xmax>
<ymax>873.8</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
<attribute>
<name>track_id</name>
<value>8</value>
</attribute>
<attribute>
<name>keyframe</name>
<value>True</value>
</attribute>
</attributes>
</object>
<object>
<name>行人</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1469.0</xmin>
<ymin>832.96</ymin>
<xmax>1489.43</xmax>
<ymax>865.8</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
<attribute>
<name>track_id</name>
<value>9</value>
</attribute>
<attribute>
<name>keyframe</name>
<value>True</value>
</attribute>
</attributes>
</object>
</annotation>
'''
# 解析XML数据
root = ET.fromstring(xml_string)
# 提取有效数据
folder = root.find('folder').text
filename = root.find('filename').text
width = int(root.find('size/width').text)
height = int(root.find('size/height').text)
objects = []
for obj in root.findall('object'):
name = obj.find('name').text
xmin = float(obj.find('bndbox/xmin').text)
ymin = float(obj.find('bndbox/ymin').text)
xmax = float(obj.find('bndbox/xmax').text)
ymax = float(obj.find('bndbox/ymax').text)
objects.append({
'name': name,
'xmin': xmin,
'ymin': ymin,
'xmax': xmax,
'ymax': ymax
})
# 打印提取的有效数据
print("Folder:", folder)
print("Filename:", filename)
print("Width:", width)
print("Height:", height)
print("Objects:")
for obj in objects:
print(obj)
```
运行这段代码,它将解析XML字符串并提取出标签中的有效数据。你可以根据需要对提取出的数据进行进一步处理或存储。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
使用cheerio将以下代码转换为json <input type="checkbox" v-model="RemitInBox" class="RemitInBox v-pristine v-valid" name="RemitInBox" value="0" v-checked="data.CheckFlag" v-disabled="data.FndDrc!='01' || data.BusiState!='10'" id="List0_RemitIn" v-click="clickBox($index,data)"> IR00252300347A IR00252300347A 2023-05-25 USD32,993.50 1/FLOKSER KIMYA SANAYI VE TICARET 1... 31980005000107125 入账 退汇 待客户确认 受理成功 打印
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
请分析以下代码中“编辑”按钮为什么没有用?编辑 <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button> 烹饪分类信息编辑 <form class="form-horizontal" name="cookClassEditForm" id="cookClassEditForm" enctype="multipart/form-data" method="post" class="mar_t15"> <label for="cookClass_cookClassId_edit" class="col-md-3 text-right">分类id:</label> <input type="text" id="cookClass_cookClassId_edit" name="cookClass.cookClassId" class="form-control" placeholder="请输入分类id" readOnly> <label for="cookClass_className_edit" class="col-md-3 text-right">分类名称:</label> <input type="text" id="cookClass_className_edit" name="cookClass.className" class="form-control" placeholder="请输入分类名称"> <label for="cookClass_cookClassDesc_edit" class="col-md-3 text-right">烹饪分类介绍:</label> <textarea id="cookClass_cookClassDesc_edit" name="cookClass.cookClassDesc" rows="8" class="form-control" placeholder="请输入烹饪分类介绍"></textarea> </form> <style>#cookClassEditForm .form-group {margin-bottom:5px;} </style> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> <button type="button" class="btn btn-primary" onclick="ajaxCookClassModify();">提交</button> function cookClassEdit(cookClassId) { $.ajax({ url : basePath + "CookClass/" + cookClassId + "/update", type : "get", dataType: "json", success : function (cookClass, response, status) { if (cookClass) { $("#cookClass_cookClassId_edit").val(cookClass.cookClassId); $("#cookClass_className_edit").val(cookClass.className); $("#cookClass_cookClassDesc_edit").val(cookClass.cookClassDesc); $('#cookClassEditDialog').modal('show'); } else { alert("获取信息失败!"); } } }); } function ajaxCookClassModify() { $.ajax({ url : basePath + "CookClass/" + $("#cookClass_cookClassId_edit").val() + "/update", type : "post", dataType: "json", data: new FormData($("#cookClassEditForm")[0]), success : function (obj, response, status) { if(obj.success){ alert("信息修改成功!"); location.href= basePath + "CookClass/frontlist"; }else{ alert(obj.message); } }, processData: false, contentType: false, }); }
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)