如何通过jQuery增加/减少某个数字的当前保证金? [英] How to increase/decrease current margin at a number by jquery?

查看:80
本文介绍了如何通过jQuery增加/减少某个数字的当前保证金?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个左边距未知的元素,如何增加其左边距为100px?

Given an element with unknown margin-left, how to increase its margin-left at a number say 100px?

例如:

假设原始边距为100px

assuming the original margin-left is 100px

预期结果是100px + 100px,因此最终是200px.

the expected result is 100px + 100px thus 200px finally.

推荐答案

$('#element-id').css('margin-left', function (index, curValue) {
    return parseInt(curValue, 10) + 100 + 'px';
});

curValue的末尾将包含'px',因此您最终将以NaN100px100px作为结果,而无需先使用parseInt.

curValue will include 'px' at the end, so you'll end up with NaN or 100px100px as your result without using parseInt first.

这篇关于如何通过jQuery增加/减少某个数字的当前保证金?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆