我有一个类名,例如“ toxics_decompose(phase)_field1”。
每当我尝试在JQUERY中通过此类名称获取数据时,都会抛出错误
HTML
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required ></textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required ></textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required ></textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required ></textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required ></textarea>
OR
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required >
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required >
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required >
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required >
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required >
JQUERY
$(".toxics_decompose(phase)_field1").each(function(i,obj){
console.log($(this).val());
});
//OR
[SEC.1] var string=$('input[name^="toxics_decompose(phase)_field1[]"]').serialize();
但是[SEC.1]中没有确定输入类型是文本区域还是数字,因此它如何工作。 注意:此处[SEC.1]仅用于参考。
$(".toxics_decompose(phase)_field1").each(function(i, obj) {
console.log($(this).val());
});
var string = $('input[name^="toxics_decompose(phase)_field1[]"]').serialize();
console.log(string)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>wer</textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>wer</textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>wer</textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required></textarea>
<textarea rows="4" cols="10" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required></textarea> OR
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required value="asd">
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>
<input type="number" class="form-control toxics_decompose(phase)_field1" name="toxics_decompose(phase)_field1[]" placeholder="" required>
在我的方案中,我使用的是数据库获取的名称“ toxics_decompose(phase)_field1”,它会根据更改而有所不同。