为什么不只在half_price 可用时才要求它。
<input type="checkbox" name="half_price" value="{{item.half_price}}"
{% if item.half_price %} required {% else %} disabled {% endif %}
>
full_price 也一样
<input type="checkbox" name="full_price" value="{{item.full_price}}"
{% if item.full_price %} required {% else %} disabled {% endif %}
>
编辑:
需要进行更改。
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="half_price" id='c01' value="{{item.half_price}}" onclick="check(this);" style="margin-top: 20px;" {% if item.half_price %}required{% else %}disabled{% endif %} > Half: ₹ {{item.half_price}}/- </h5>
<span class="checkmark"></span>
</label>
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="full_price" id='c02' value={{item.full_price}} onclick="check(this);" {% if item.full_price %}required{% else %}disabled{% endif %} > Full : ₹ {{item.full_price}}/- </h5>
<span class="checkmark"></span>
</label>
<input style="margin-left: 10px;" type="submit" class="button" value="ADD">
有数据
{
item: {
half_price: 40,
full_price: 80
}
}
会翻译成
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="half_price" id='c01' value="40" onclick="check(this);" style="margin-top: 20px;" required > Half: ₹ 40/- </h5>
<span class="checkmark"></span>
</label>
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="full_price" id='c02' value=80 onclick="check(this);" required > Full : ₹ 80/- </h5>
<span class="checkmark"></span>
</label>
<input style="margin-left: 10px;" type="submit" class="button" value="ADD">
对于数据
{
item: {
half_price: 40
}
}
将转换为
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="half_price" id='c01' value="40" onclick="check(this);" style="margin-top: 20px;" required > Half: ₹ 40/- </h5>
<span class="checkmark"></span>
</label>
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="full_price" id='c02' value= onclick="check(this);" disabled > Full : ₹ /- </h5>
<span class="checkmark"></span>
</label>
<input style="margin-left: 10px;" type="submit" class="button" value="ADD">
对于数据
{
item: {}
}
会翻译成
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="half_price" id='c01' value="" onclick="check(this);" style="margin-top: 20px;" disabled > Half: ₹ /- </h5>
<span class="checkmark"></span>
</label>
<label class="radio-inline">
<h5> <input type="checkbox" class="radioCheck" name="full_price" id='c02' value= onclick="check(this);" disabled > Full : ₹ /- </h5>
<span class="checkmark"></span>
</label>
<input style="margin-left: 10px;" type="submit" class="button" value="ADD">
更新:
在 cmets 中解决问题。
如果您只想要这些值,那么这些就是需要进行的更改。
<label class="radio-inline">
<h5> <input type="radio" class="radioCheck" name="price" id='c01' value="{{item.half_price}}" onclick="check(this);" style="margin-top: 20px;" {% if item.half_price %}required{% else %}disabled{% endif %} > Half: ₹ {{item.half_price}}/- </h5>
<span class="checkmark"></span>
</label>
<label class="radio-inline">
<h5> <input type="radio" class="radioCheck" name="price" id='c02' value={{item.full_price}} onclick="check(this);" {% if item.full_price %}required{% else %}disabled{% endif %} > Full : ₹ {{item.full_price}}/- </h5>
<span class="checkmark"></span>
</label>
<input style="margin-left: 10px;" type="submit" class="button" value="ADD">
对于数据
{
item: {
"half_price": 80,
"full_price": 160
}
}
会翻译成
<label class="radio-inline">
<h5> <input type="radio" class="radioCheck" name="price" id='c01' value="80" onclick="check(this);" style="margin-top: 20px;" required > Half: ₹ 80/- </h5>
<span class="checkmark"></span>
</label>
<label class="radio-inline">
<h5> <input type="radio" class="radioCheck" name="price" id='c02' value=160 onclick="check(this);" required > Full : ₹ 160/- </h5>
<span class="checkmark"></span>
</label>
<input style="margin-left: 10px;" type="submit" class="button" value="ADD">