
你好,如下图:
祝愉快!
变量赋值的格式:
变量名=值
访问变量值
要取用一个变量的值,只需在变量名前面加一个$ 。
( ATTENTION: Don't keep blank between the variable with the equal operator '=' )
举例:
#!/bin/bash
# 对变量赋值:
a="hello world" #等号两边均不能有空格存在
# 打印变量a的值:
echo -e "A is: $a\n"
备注:
1). bash中变量赋值,等号两边均不能有空格存在;
使用自己喜欢的编辑器,输入上述内容,并保存为文件test_hello.bsh,然后执行 chmod +x test_hello.bsh使其具有执行权限,最后输入 ./test_hello或bash test_hello.bsh执行该脚本。
参考资料
编程之给变量赋值的五种方法.个人图书馆[引用时间2018-1-5]
var $element = $(this), placeholder = $element.attr('placeholder')if (placeholder) {
// 文本框ID
var elementId = $element.attr('id')
if (!elementId) {
var now = new Date()
elementId = 'lbl_placeholder' + now.getSeconds() + now.getMilliseconds()
$element.attr('id', elementId)
}
// 添加label标签,用于显示placeholder的值
var $label = $('<label>', {
html: $element.val() ? '' : placeholder,
'for': elementId,
css:
{
position: 'absolute',
cursor: 'text',
color: '#a9a9a9',
fontSize: $element.css('fontSize'),
fontFamily: $element.css('fontFamily')
}
}).insertAfter($element)
// 绑定事件
var _setPosition = function () {
$label.css({ marginTop: GetStringNumValue($element.css('marginTop')) + 8 + 'px', marginLeft: '-' + (GetStringNumValue($element.css('width')) - 6) + 'px' })
}
var _resetPlaceholder = function () {
if ($element.val()) { $label.html(null)}
else {
_setPosition()
$label.html(placeholder)
}
}
_setPosition()
$element.on('focus blur input keyup propertychange resetplaceholder', _resetPlaceholder)
代码很简单,需注意的是:
1、label 的 margin-top / margin-left,因为我们的项目用了 bootstrap 框架,已设定了输入框的内间距为 "padding: 4px 6px" 所以这里需缩进对应的像素值。
2、GetStringNumValue() 是我们自己定义的方法,使用正则表达式,用于把字符串中的数字提取,例如 "123px" 返回 123。
3、对于 IE 中不支持的版本,propertychange 真是一个好方法,完美的结合了!...
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)