小编Fab*_* N.的帖子

如何在刚刚出现的元素上使用jQuery设置焦点

我有一个文件就绪块如下:

$(document).ready(function () {
    $('#addTagLink').click(function () {
        $('#addTagField').show();
        $('#addTagField').val("");
        $('#addTagField').focus();
    });
});
Run Code Online (Sandbox Code Playgroud)

addTagField是一个常规文本输入,在页面加载时由css设置display:none.

当用户单击addTagLink 元素时,输入字段会正确显示,但焦点不会按预期设置到字段.

我认为它必须与display:none/show()功能有关,因此将其更改$('#addTagField').focus();为另一个$('#name').focus();完美运行的字段.

任何人都可以先建议我为什么看到这个问题,其次,如何解决它?

jquery focus show setfocus

2
推荐指数
2
解决办法
4万
查看次数

Android:如何使SearchView占用ActionBar中的整个水平空间?

在下面的屏幕截图中,SearchView窗口小部件ActionBar不占用整个可用空间.

在此输入图像描述

我需要它占据所有水平空间ActionBar(因此它横跨整个屏幕).

我尝试了什么:

  • 以编程方式,尝试了这个onCreateOptionsMenu:

    View searchViewView = (View) searchView;
    searchViewView.getLayoutParams().width=LayoutParams.MATCH_PARENT;`
    
    Run Code Online (Sandbox Code Playgroud)

    这给出了:

    java.lang.NullPointerException: Attempt to write to
    field 'int android.view.ViewGroup$LayoutParams.width' on a null
    object reference ...       
    TestActionBarTwo.MainActivity.onCreateOptionsMenu(MainActivity.java:57)
    
    Run Code Online (Sandbox Code Playgroud)
  • 并在菜单资源中:

    android:layout_width="match_parent"似乎并没有造成任何影响.

  • 我也试过android:layout_weight="1"(假设 ActionBar有a LinearLayout),但这也不起作用.

那么有没有一种方法SearchView(没有图标化)占据整个水平空间ActionBar


编辑1

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        Log.i(TAG, "onCreateOptionsMenu OF MainActivity CALLED."); //check

        getMenuInflater().inflate(R.menu.activity_main_action_bar_menu, menu);

        getSupportActionBar().setDisplayShowHomeEnabled(false);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        // SearchAction
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        MenuItem searchMenuItem = menu.findItem(R.id.action_search);
        SearchView searchView …
Run Code Online (Sandbox Code Playgroud)

android android-layout layoutparams android-actionbar searchview

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

Python 函数 - 将完整的 if 条件作为参数传递

在 Python 中是否可以仅在必要时将某个条件作为参数传递给函数?例如:一个完整​​的 if 条件:

  # /!\ checking if customer_name is NULL (NOT NULL field in destination database)
  if row['customer_name'] == NULL:
    row['customer_name'] = row['contact_name']
Run Code Online (Sandbox Code Playgroud)

我正在编写一个脚本,它将自动将数据从 mysql 迁移到 postgresql。有些表在两个数据库(源和目标)中具有相同的结构,有些表在结构上不同,而有些表只有数据类型不同。

我试图了解是否可以在函数内部“注入”一个条件,以便对上面提到的所有 3 种情况使用相同的代码段,条件每次都会不同。

以下是一个示例(我正在调查注入可能性的代码段为黄色 -> 将其作为参数传递):

def migrate_table(select_query, insert_query, tmp_args):
  # Cursors initialization
  cur_psql = cnx_psql.cursor()

  cur_msql.execute(select_query)

  args = []
  for row in cur_msql:

    # /!\ checking if customer_name is NULL (NOT NULL field in destination database)
    if row['customer_name'] == NULL:
      row['customer_name'] = row['contact_name']
      args.append(cur_psql.mogrify(tmp_args, row))
    args_str = ','.join(args)

  if len(args_str) …
Run Code Online (Sandbox Code Playgroud)

python parameters if-statement function

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

Visual Studio单元测试拒绝运行

我开始使用Visual Studio和内置单元测试器测试学校项目.该项目是一个用C#编写的类库.到目前为止,我所有的测试都有效.但是,我仍然有一个不能运行的测试.它没有通过或失败,它根本就没有运行.没有给出错误消息,我无法让它运行或调试或任何东西.这是我正在尝试的测试:

[TestMethod()]
    public void PublicDecimalEqualityTest2()
    {
        Formula form1 = new Formula("2.3232000+3.00");
        Formula form2 = new Formula("2.3232+3.0000");
        Assert.IsTrue(form1==form2);
    }
Run Code Online (Sandbox Code Playgroud)

我的类的"=="运算符已正确定义.奇怪的是,这个测试运行并通过:

[TestMethod()]
    public void PublicDecimalEqualityTest()
    {
        Formula form1 = new Formula("2.3232000+3.00");
        Formula form2 = new Formula("2.3232+3.0000");
        Assert.IsTrue(form1.Equals(form2));
    }
Run Code Online (Sandbox Code Playgroud)

知道为什么发布的第一个测试不会运行?

编辑:这是==运营商的代码:

public static bool operator ==(Formula f1, Formula f2) {
    if (f1==null && f2==null)
    { return true; }
    if (f1==null || f2==null)
    {return false;}
    if (f1.GetFormulaBasic()==f2.GetFormulaBasic())
    { return true; }
    else
    { return false;}
}
Run Code Online (Sandbox Code Playgroud)

GetFormulaBasic()只需从类中返回一个私有字符串.希望这可以帮助.

c# unit-testing visual-studio-2013

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

将我的函数转换为一个类

我有以下代码是我为一门运行良好的课程编写的:

def reverse_iter(iterable):
    """Return a generator that yields items from iterable in reverse order"""
    last = len(iterable) - 1
    while last >= 0:
        yield iterable[last]
        last -= 1
Run Code Online (Sandbox Code Playgroud)

作业的下一部分是把这个函数变成一个类。我知道这不切实际,但这是被问到的。我对类的了解非常有限,但我想出了以下代码:

class ReverseIter:
    """Class whose instances iterate the initial iterable in reverse order"""
    def __init__(self, iterable):
        self.iterable = iterable

    def iterreverse(self):
        last = len(self.iterable) - 1
        while last >= 0:
            yield self.iterable[last]
            last -= 1  

nums = [1, 2, 3, 4]
it = ReverseIter(nums)
print(iter(it) is it)
print(next(it) == 4)
print(next(it))
print(next(it)) …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

在div中显示javascript数组

我正在尝试制作一个基本的待办事项应用程序。

这是我到目前为止所做的;

  • 当用户单击按钮时,会出现提示,要求用户输入任务。

  • 然后任务将被存储在一个数组中

  • 我已在控制台中显示了该数组。但是,我在网页上显示数组时遇到问题:

var toDoItems = [];
var parsed = "";

document.getElementById("addItem").onclick = function() {
  var userInput = prompt("Enter your Todo: ")
  toDoItems.push = userInput;
  console.log(toDoItems);
}
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">

<head>
  <link href='https://fonts.googleapis.com/css?family=Lato:100,300,400,300italic' rel="stylesheet" type="text/css">
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <title>To Do List</title>
</head>

<body>
  <h1>My Tasks</h1>
  <button id="addItem">Add item</button>
  <div id="item-list">
  </div>
  <script src="js/script.js"></script>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

html javascript css arrays

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

Angular 和 Ionic-v4 离子选择弹出窗口不起作用

我想以弹出模式以编程方式打开 ionSelect。

@ViewChild('selectNotificationList') selectNotificationList: IonSelect;
Run Code Online (Sandbox Code Playgroud)

打开离子选择的方法是:

clickNotificationNumber() {
    this.selectNotificationList.interface = 'popover';
    this.selectNotificationList.open();
}
Run Code Online (Sandbox Code Playgroud)

HTML是:

<ion-card slot="end" class="langCard">
    <ion-card-content>
        <ion-select interface ="popover"  (ionChange)="readNotification($event)" #selectNotificationList>
            <ion-select-option *ngFor="let message of notificationList let notificationIndex = index"  value="{{message.id}}">
                {{message.notificationOptions.body}}</ion-select-option>
        </ion-select>
    </ion-card-content>
</ion-card>
Run Code Online (Sandbox Code Playgroud)

ionic-framework ionic2 angular ionic4

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

(Python)将列表中的项目转换为列表

我想将列表中的项目作为列表存储(即每个二进制位将是新列表中的索引)但我似乎无法实现这一点:

encoded = []
for value in redChannelData:
    encoded1 = bin(value)[2:]
    encoded.append(encoded1)

redchannelbinarylist = [[] for binary in encoded] 

print(redchannelbinarylist)
print(encoded)
Run Code Online (Sandbox Code Playgroud)

产量

['101110', '110001', '110010', '110011', '110101', '110101', '110110', '111000', '111011', '111011', '111100', '111101', '111110', '111110', '1000000', '1000000', '1000001']
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

[[1, 0, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1], ...]
Run Code Online (Sandbox Code Playgroud)

python

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

如何将css应用于textarea内的特定词

我想将一种风格应用于特定的单词textarea.这是我的textarea文本:

<textarea id="shareMessage" name="shareMessage" required> I found something you’ll really want </textarea>
Run Code Online (Sandbox Code Playgroud)

我想把'某事'这个词改成斜体.我尝试在textarea中使用italic标签,但问题是我不能在textarea中使用任何标签.

html css

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