gpt4 book ai didi

javascript - 在 javascript 函数中更改 span 类属性值

转载 作者:行者123 更新时间:2023-11-28 05:16:14 27 4
gpt4 key购买 nike

我有以下代码(简化)以及后面的 JavaScript。当 $quantity=0 且 status=1 时,我尝试发出一条警报消息,然后更改 span class="switch-selection"的 padding-left 值。我对如何更改填充的语法感到困惑。

<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>

最佳答案

您无法更改 jquery 对象上的属性 style,而是使用 jquery css 函数

$(this).find(".switch > span").css('paddingLeft',"60px");

关于javascript - 在 javascript 函数中更改 span 类属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40967753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com