小编Tri*_*ych的帖子

如何简化这个Javascript函数?

我正在尝试扩展这个但是在创建JS函数时我有点绿.我设法自己走了这么远,但唉......

当跨度获得任何值(在本例中为城市名称)时,我希望选择框自动匹配它.而且我想通过摆脱所有这些来扩展它,如果是的话.

$(document).ready(function() {
  $('select#field1 option').removeAttr('selected');
  var whereEvent = $('span#field2').html();
  if (whereEvent == 'New York') {
    $('select#field1 option[value=New York]').attr('selected', 'true');
  } else if (whereEvent == 'Los Angeles') {
    $('select#field1 option[value=Los Angeles]').attr('selected', 'true');
  } else if (whereEvent == 'Tokyo') {
    $('select#field1 option[value=Tokyo]').attr('selected', 'true');
  } else if (whereEvent == 'London') {
    $('select#field1 option[value=London]').attr('selected', 'true');
  } else if (whereEvent == 'Sydney') {
    $('select#field1 option[value=Sydney]').attr('selected', 'true');
  } else if (whereEvent == 'Paris') {
    $('select#field1 option[value=Paris]').attr('selected', 'true');
  }
});
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?我保证我会感激你的帮助.谢谢.

javascript jquery

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

为什么我的Python测试生成器根本不起作用?

这是一个测试yield使用的示例脚本......我做错了吗?它总是返回'1'......

#!/usr/bin/python

def testGen():
    for a in [1,2,3,4,5,6,7,8,9,10]:
         yield a

w = 0
while w < 10:
    print testGen().next()
        w += 1
Run Code Online (Sandbox Code Playgroud)

python testing yield generator

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

是否可以使用BeautifulSoup编辑内联代码?

我知道用beautifulsoup编辑文本的能力,是否可以编辑href链接?我希望能够说出<a href="/foo/bar/">并使用beautifulsoup来改变它<a href="http://www.foobarinc.com/foo/bar/">.我不确定如何使用beautifulsoup来做到这一点?任何帮助,非常感谢.

python beautifulsoup

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

在Python中实例化类的替代方法

我目前正在编写我的python类并像这样实例化它们

class calculations_class():
    def calculate(self):
        return True

Calculations = calculations_class()
Run Code Online (Sandbox Code Playgroud)

我想知道我是否正确地执行此操作,或者是否有任何其他方法来实例化它们.谢谢!

python

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

Python:查找并指向字符串的中点

我刚开始学习Python(作为我的第一语言,所以我几乎什么都不知道)并且遇到了这个问题.

找到单词的中点,并使用插入符"^"指向它.

例,

Computer
   ^
Run Code Online (Sandbox Code Playgroud)

感谢任何人可以给我的提示.

python

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

标签 统计

python ×4

beautifulsoup ×1

generator ×1

javascript ×1

jquery ×1

testing ×1

yield ×1