相关疑难解决方法(0)

使用jQuery更改输入字段的类型

$(document).ready(function() {
    // #login-box password field
    $('#password').attr('type', 'text');
    $('#password').val('Password');
});
Run Code Online (Sandbox Code Playgroud)

这应该更改正常文本字段的#password输入字段(with id="password"),type password然后填写文本"Password".

但它不起作用.为什么?

这是表格:

<form enctype="application/x-www-form-urlencoded" method="post" action="/auth/sign-in">
  <ol>
    <li>
      <div class="element">
        <input type="text" name="username" id="username" value="Prihlasovacie meno" class="input-text" />
      </div>
    </li>
    <li>
      <div class="element">
        <input type="password" name="password" id="password" value="" class="input-text" />
      </div>
    </li>
    <li class="button">
      <div class="button">
        <input type="submit" name="sign_in" id="sign_in" value="Prihlási?" class="input-submit" />
      </div>
    </li>
  </ol>
</form>
Run Code Online (Sandbox Code Playgroud)

javascript jquery html-input

200
推荐指数
9
解决办法
29万
查看次数

使用单选按钮在Django admin中选择项目

这是我的models.py的一部分:

class Person(models.Model):
    birth_year = WideYear(null=True, blank=True)
    birth_year_uncertain = models.BooleanField()
    death_year = WideYear(null=True, blank=True)
    death_year_uncertain = models.BooleanField()
    flourit_year = WideYear(null=True, blank=True)
    flourit_year_uncertain = models.BooleanField()
    FLOURIT_CHOICES = (
        (u'D', u'Birth and death dates'),
        (u'F', u'Flourit date'),
    )
    use_flourit = models.CharField('Date(s) to use', max_length=2, choices=FLOURIT_CHOICES)
    def __unicode__(self):
        if self.personname_set.filter(default_name__exact=True):
            name = z(self.personname_set.filter(default_name__exact=True)[0])
        else:
            name = u'[Unnamed person]'
        if self.use_flourit == u'D':
            dates = '%s - %s' % (z(self.birth_year), z(self.death_year))
        else:
            dates = 'fl. %s' % (z(self.flourit_year))
        return '%s (%s)' % (name, dates) …
Run Code Online (Sandbox Code Playgroud)

javascript django-forms django-admin

23
推荐指数
1
解决办法
2658
查看次数

jQuery将input type = text更改为textarea

我有一个隐藏的领域.在下降事件之后,它需要转换为'textarea'.

这个:

      excerpt = $(parent).find('#excerpt').attr('type', 'textarea');
      excerpt.val('textarea');
Run Code Online (Sandbox Code Playgroud)

生产

财产不能改变

错误

此方法:将 元素类型从隐藏更改为输入

marker = $('<span />').insertBefore('#myInput');
$('#myInput').detach().attr('type', 'textarea').insertAfter(marker);
marker.remove();
Run Code Online (Sandbox Code Playgroud)

没有使用'textarea',但只适用于'text'.添加:

.val('HERE')
Run Code Online (Sandbox Code Playgroud)

致:

$('#myInput').detach().attr('type', 'textarea').val('HERE').insertAfter(marker);
Run Code Online (Sandbox Code Playgroud)

line确实导致文本框的值发生变化,因此选择器正在工作,并且<span>正在插入和删除元素.

这是一个不可逾越的安全问题吗?或者有办法吗?

forms jquery input

4
推荐指数
1
解决办法
3738
查看次数

为什么这段代码jquery不起作用?

可能重复:
将密码字段更改为带有jquery复选框的文本

该代码应检查是否选中了复选框,然后将密码字段从密码更改为常规文本,反之亦然.

$('#cpassword_lf').change(function(){
     if($('#cpassword_lf').is(':checked'))
     {
        $('#password_loginform').attr('type', 'text'); 
     }
     else
     {
         $('#password_loginform').attr('type', 'password'); 
     }  
 });
Run Code Online (Sandbox Code Playgroud)

javascript jquery

2
推荐指数
1
解决办法
2532
查看次数