python 生成htmltag_Python html.TAG属性代码示例

# 需要导入模块: from gluon import html [as 别名]

# 或者: from gluon.html import TAG [as 别名]

def __call__(self, field, value, **attributes):

default = dict(

_type='text',

value=(not value is None and str(value)) or '',

)

attr = StringWidget._attributes(field, default, **attributes)

div_id = self.keyword + '_div'

attr['_autocomplete'] = 'off'

if self.is_reference:

key2 = self.keyword + '_aux'

key3 = self.keyword + '_auto'

attr['_class'] = 'string'

name = attr['_name']

if 'requires' in attr:

del attr['requires']

attr['_name'] = key2

value = attr['value']

record = self.db(

self.fields[1] == value).select(self.fields[0]).first()

attr['value'] = record and record[self.fields[0].name]

attr['_onblur'] = "jQuery('#%(div_id)s').delay(1000).fadeOut('slow');" % \

dict(div_id=div_id, u='F' + self.keyword)

attr['_onkeyup'] = "jQuery('#%(key3)s').val('');var e=event.which?event.which:event.keyCode; function %(u)s(){jQuery('#%(id)s').val(jQuery('#%(key)s :selected').text());jQuery('#%(key3)s').val(jQuery('#%(key)s').val())}; if(e==39) %(u)s(); else if(e==40) {if(jQuery('#%(key)s option:selected').next().length)jQuery('#%(key)s option:selected').attr('selected',null).next().attr('selected','selected'); %(u)s();} else if(e==38) {if(jQuery('#%(key)s option:selected').prev().length)jQuery('#%(key)s option:selected').attr('selected',null).prev().attr('selected','selected'); %(u)s();} else if(jQuery('#%(id)s').val().length>=%(min_length)s) jQuery.get('%(url)s?%(key)s='+encodeURIComponent(jQuery('#%(id)s').val()),function(data){if(data=='')jQuery('#%(key3)s').val('');else{jQuery('#%(id)s').next('.error').hide();jQuery('#%(div_id)s').html(data).show().focus();jQuery('#%(div_id)s select').css('width',jQuery('#%(id)s').css('width'));jQuery('#%(key3)s').val(jQuery('#%(key)s').val());jQuery('#%(key)s').change(%(u)s);jQuery('#%(key)s').click(%(u)s);};}); else jQuery('#%(div_id)s').fadeOut('slow');" % \

dict(url=self.url, min_length=self.min_length,

key=self.keyword, id=attr['_id'], key2=key2, key3=key3,

name=name, div_id=div_id, u='F' + self.keyword)

if self.min_length == 0:

attr['_onfocus'] = attr['_onkeyup']

return TAG[''](INPUT(**attr), INPUT(_type='hidden', _id=key3, _value=value,

_name=name, requires=field.requires),

DIV(_id=div_id, _style='position:absolute;'))

else:

attr['_name'] = field.name

attr['_onblur'] = "jQuery('#%(div_id)s').delay(1000).fadeOut('slow');" % \

dict(div_id=div_id, u='F' + self.keyword)

attr['_onkeyup'] = "var e=event.which?event.which:event.keyCode; function %(u)s(){jQuery('#%(id)s').val(jQuery('#%(key)s').val())}; if(e==39) %(u)s(); else if(e==40) {if(jQuery('#%(key)s option:selected').next().length)jQuery('#%(key)s option:selected').attr('selected',null).next().attr('selected','selected'); %(u)s();} else if(e==38) {if(jQuery('#%(key)s option:selected').prev().length)jQuery('#%(key)s option:selected').attr('selected',null).prev().attr('selected','selected'); %(u)s();} else if(jQuery('#%(id)s').val().length>=%(min_length)s) jQuery.get('%(url)s?%(key)s='+encodeURIComponent(jQuery('#%(id)s').val()),function(data){jQuery('#%(id)s').next('.error').hide();jQuery('#%(div_id)s').html(data).show().focus();jQuery('#%(div_id)s select').css('width',jQuery('#%(id)s').css('width'));jQuery('#%(key)s').change(%(u)s);jQuery('#%(key)s').click(%(u)s);}); else jQuery('#%(div_id)s').fadeOut('slow');" % \

dict(url=self.url, min_length=self.min_length,

key=self.keyword, id=attr['_id'], div_id=div_id, u='F' + self.keyword)

if self.min_length == 0:

attr['_onfocus'] = attr['_onkeyup']

return TAG[''](INPUT(**attr), DIV(_id=div_id, _style='position:absolute;'))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值