我有以下代碼(簡化)以及下面的JavaScript。當$ quantity = 0和status = 1時,我試圖提出一條警告消息,然後更改span class =「switch-selection」的填充左值。我很困惑如何改變填充的語法。在javascript函數中更改span類別屬性值
<table>
<?php $ind = 0; ?>
<?php foreach ($this->items as $item) {;?>
<tr id="<?php echo $item['id']; ?>">
<td class="Quantity"><span>$item['quantity']</span></td>
<td class="status">
<label for="a" class="switch-label switch-label-off">Active</label>
<input type="radio" id="a" name="test1" class="switch-label switch-label-off" value="1" <?php if ($item['active'] == 1)> >
<label for="b" class="switch-label switch-label-off">Active</label>
<input id="b" type="radio" name="test1" class="switch-label switch-label-on" value="0" <?php if ($item['active'] == 1)> >
<span class="switch-selection"></span>
</td>
</tr>
<?php $ind++; ?>
<?php } ?>
</table>
<script type="text/javascript">
$(document).ready(function() {
if (typeof ind == "undefined") {
ind = 0;
}
$("input").on('change',function(){
var status = this.value;
var quantity = $(this).closest("tr").find(".Quantity > span").text();
if (quantity == 0 && status == 1) {
window.alert("To activate a product, your quantity must be at least 1.");
$(this).find(".switch > span")..style.paddingLeft = "60px";
}
});
</script>
使用'的CSS後({ '填充左': '60像素'})' – Tushar
有一個錯字或這裏一個錯誤'..style.paddingLeft ='(2點) –