<form action="" class="s-form"> <div class="s-field"> <div class="left">数据集名称</div> <div class="right"> <input type="text" name="" id="" class="s-input" style="width: 380px; height: 32px;"> </div> </div> <div class="s-field"> <div class="left">标注类型</div> <div class="right"> <div class="radio-item"> <input type="radio" name="object1" id=""> <label for="object1">物体检测</label> </div> <div class="radio-item"> <input type="radio" name="object2" id=""> <label for="object2">语义分割</label> </div> </div> </div> <button class="s-button">创建并导入</button> <button class="s-button">完成创建</button> <button class="s-button">取消</button> </form>优化代码,可以改变标签类名及id名,实现物体检测和语义分割的单选框只能选择一个,将用户输入的数据集名称和选择的单选框通过Ajax传递给后台
时间: 2024-02-10 13:06:49 浏览: 85
以下是优化后的代码,修改了标签类名及id名,实现了单选框只能选择一个,添加了Ajax实现将用户输入的数据集名称和选择的单选框传递给后台:
```
<form action="" class="form-dataset">
<div class="field">
<div class="field-label">数据集名称</div>
<div class="field-input">
<input type="text" name="dataset-name" class="input-text" style="width: 380px; height: 32px;">
</div>
</div>
<div class="field">
<div class="field-label">标注类型</div>
<div class="field-input">
<div class="radio-group">
<div class="radio-item">
<input type="radio" name="annotation-type" id="object-detection" value="object-detection">
<label for="object-detection">物体检测</label>
</div>
<div class="radio-item">
<input type="radio" name="annotation-type" id="semantic-segmentation" value="semantic-segmentation">
<label for="semantic-segmentation">语义分割</label>
</div>
</div>
</div>
</div>
<button type="button" class="button-create-import">创建并导入</button>
<button type="button" class="button-create">完成创建</button>
<button type="button" class="button-cancel">取消</button>
</form>
<script>
$(function() {
// 单选框只能选择一个
$('.radio-item input[type="radio"]').on('click', function() {
$(this).closest('.radio-group').find('input[type="radio"]').prop('checked', false);
$(this).prop('checked', true);
});
// 创建并导入按钮事件
$('.button-create-import').on('click', function() {
var datasetName = $('input[name="dataset-name"]').val();
var annotationType = $('input[name="annotation-type"]:checked').val();
// 发送Ajax请求
$.ajax({
url: '后台处理程序的URL',
type: 'POST',
data: {
datasetName: datasetName,
annotationType: annotationType
},
success: function(data) {
// 处理成功后的逻辑
},
error: function() {
// 处理失败后的逻辑
}
});
});
// 完成创建按钮事件
$('.button-create').on('click', function() {
// 处理完成创建的逻辑
});
// 取消按钮事件
$('.button-cancel').on('click', function() {
// 处理取消的逻辑
});
});
</script>
```
阅读全文