在MVVM架构中设置控制焦点的好习惯是什么.
我设想它的方式是使用ViewModel上的属性,它会在需要时触发焦点更改.并且让UI控件绑定/侦听该属性,以便在它更改时,将设置适当的焦点.
我将其视为ViewModel,因为我希望在ViewModel执行某个操作后设置焦点,例如加载某些数据.
什么是最佳做法?
当用户点击"回复"按钮时,我有这个代码来关注textarea:
$('#reply_msg').live('mousedown', function() {
$(this).hide();
$('#reply_holder').show();
$('#reply_message').focus();
});
Run Code Online (Sandbox Code Playgroud)
它显示了回复表单,但textarea不会关注.我正在通过AJAX添加textarea,这就是我使用的原因.live().我添加的框显示(我甚至#reply_msg通过AJAX 添加,当我按下鼠标时会发生一些事情),但它不会关注textarea.
我的HTML看起来像:
<div id="reply_msg">
<div class="replybox">
<span>Click here to <span class="link">Reply</span></span>
</div>
</div>
<div id="reply_holder" style="display: none;">
<div id="reply_tab"><img src="images/blank.gif" /> Reply</div>
<label class="label" for="reply_subject" style="padding-top: 7px; width: 64px; color: #999; font-weight: bold; font-size: 13px;">Subject</label>
<input type="text" id="reply_subject" class="input" style="width: 799px;" value="Re: <?php echo $info['subject']; ?>" />
<br /><br />
<textarea name="reply" id="reply_message" class="input" spellcheck="false"></textarea>
<br />
<div id="reply_buttons">
<button type="button" class="button" id="send_reply">Send</button>
<button type="button" class="button" …Run Code Online (Sandbox Code Playgroud) 我期待实现这一目标: http://getbootstrap.com/javascript/#popovers-examples -滚动到"现场演示"和打红酥料饼按钮,在Chrome OS X上....这是完美的美丽
现在去这里(问题小孩):http://yoyo.io/javascript/#popovers -它概括蓝色,aaaargh.
如果你检查一下,你会看到一连串的CSS努力将我删除!它看起来在Safari和Firefox中是正确的,但在Chrome中没有用!
任何人 - 我在俯瞰什么?
提前谢谢了!
哪些网络浏览器/版本支持document.activeElement?
此属性可让您查看哪个元素处于活动状态/具有焦点.
实现之间是否存在任何主要问题/差异?
import { Component, ViewChild} from '@angular/core';
import { Keyboard } from 'ionic-native';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
@ViewChild('input') myInput ;
constructor() {}
ionViewDidLoad() {
setTimeout(() => {
Keyboard.show() // for android
this.myInput.setFocus();
},150);
}
}
Run Code Online (Sandbox Code Playgroud)
1)导入"ViewChild"
import {Component, ViewChild} from '@angular/core';
2)在html模板中创建对输入的引用:
<ion-input #focusInput></ion-input>
Run Code Online (Sandbox Code Playgroud)
3)使用@ViewChild访问您刚才引用的输入组件.
@ViewChild('focusInput') myInput ;
4)触发焦点
每次加载视图/页面时,使用ionViewLoaded()方法触发它.
需要setTimeout
ionViewLoaded() {
setTimeout(() => {
Keyboard.show() // for android
this.myInput.setFocus();
},150); //a least 150ms.
}
Run Code Online (Sandbox Code Playgroud)
4)在Android上显示键盘
import { Keyboard } from 'ionic-native';
调用Keyboard.show()在Android上调用键盘.
5)在iOS上显示键盘 …
我在Java中使用Swing创建了一个表单.在表单中我使用了一个文本字段,每当我按下键时我都必须设置焦点.如何在Java中设置焦点在特定组件上?
一个很好的例子就是在Twitter启动屏幕(首次启动应用程序时看到的带有大图标的屏幕),或者甚至只是在关注应用程序图标时查看应用程序托盘.
基本上我需要突出显示一个ImageView,其中突出显示在ImageView中的图像轮廓,看起来它是该图像的边框.我还想自定义高光,使其成为一种特定的颜色,并使其淡出.
谢谢,
groomsy
当我的活动ScrollView布局和EditTexts开始时,EditTexts得到焦点并且Android OnScreen键盘打开.
我怎么能避免这种情况?
当我使用LinearLayout和RelativeLayout没有ScrollView它时,它不会发生.
我已经尝试过这种方式了,但它确实有效,但这不是一个好方法:
TextView TextFocus = (TextView) findViewById(R.id.MovileLabel);
TextFocus.setFocusableInTouchMode(true);
TextFocus.requestFocus();
Run Code Online (Sandbox Code Playgroud)
接下来你有一些我的布局有这个问题的例子,当这个Activity开始时,焦点转到第一个EditText,描述和Android键盘自动打开,这非常烦人.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px">
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/UserLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13px"
android:text="@string/userlabel"/>
<TextView
android:id="@+id/User"
android:layout_alignBaseline="@id/UserLabel"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"/>
</RelativeLayout>
<View
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#808080"
android:layout_marginTop="5px"
android:layout_marginBottom="12px"/>
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/DescriptionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/desclabel"
android:layout_marginTop="13px"/>
<EditText
android:id="@+id/Description"
android:layout_alignBaseline="@id/DescriptionLabel" …Run Code Online (Sandbox Code Playgroud) 我想知道为什么这段代码无法集中文本框......?
private void sendEmail_btn_Click(object sender, EventArgs e)
{
String sendTo = recipientEmail_tbx.Text.Trim();
if (!IsValidEmailAddress(sendTo))
{
MessageBox.Show("Please Enter valid Email address","Cognex" MessageBoxButtons.OK, MessageBoxIcon.Error);
recipientEmail_tbx.Focus();
}
}
Run Code Online (Sandbox Code Playgroud) 该CSS3 DOC hover和:关于会谈的焦点,这似乎完全一样的我.两者有什么不同?我没看到什么?
谢谢!