将数据属性添加到标记并使用JQuery检索它(Add a data attribute to an a tag and retrieve it using JQuery)
我有一点问题。 我有几个标签。 我想为每个
data
属性分配一个data
属性,并使用JQuery
引用data
属性的值。 然后,我想将表单中隐藏字段的值设置为此data
属性。但是,我不确定如何做到这一点。 目前我有这个链接。
<a href="" class="myclass" name="hello">Say Hello</a>
在我的
JQuery
我希望能够获得name
值....像这样......
$(".myclass").click(function (e) { e.preventDefault(); console.log(e.attr('name')); });
并输出值
hello
I'm having a bit of a problem. I have several
a
tags. I would like to assign adata
attribute to each and reference the value of thedata
attribute usingJQuery
. I would then like to set the value of a hidden field in my form to thisdata
attribute.However, I am unsure of how to do this. Currently I have this link.
<a href="" class="myclass" name="hello">Say Hello</a>
In my
JQuery
I would like to be able to get thename
value....Something like this ....
$(".myclass").click(function (e) { e.preventDefault(); console.log(e.attr('name')); });
and output the value
hello
原文:
最满意答案
textBox1.Focus(); textBox1.SelectionStart = textBox1.Text.Length;
textBox1.Focus(); textBox1.SelectionStart = textBox1.Text.Length;
相关问答
更多-
首先,每当你问这样的问题时,你必须付出一些努力并展示你所尝试过的东西,以便人们愿意帮助你。 以此作为未来问题的注释。 话虽如此,你必须为你的TextBox控件的TextChanged事件添加一个处理程序。 然后,您必须根据需要更改属性: private void textBox1_TextChanged(object sender, EventArgs e) { //PUT THE BUSINESS LOGIC IN HERE if(textBox1.Text = "") { ...
-
将焦点设置为TextBox(Set focus to TextBox)[2022-02-17]
这有帮助吗? this.ActiveControl = textBox1; This seems to be a Silverlight bug. I've used the TextChanged event on the TextBox, and set the Focus() in there. Kind of an ugly workaround, but it worked for me. If anybody has another solution, please post. -
在一个按钮上输入焦点,同时仍然可以输入文本框(Enter focus on a button while still being able to type in a textbox)[2022-08-23]
你不需要关注两个控件来获得你想要的行为(我假设) 。 只需将父窗体或对话框的AcceptButton属性设置为您正在讨论的按钮; 它的Click事件应该在您按下ENTER键时触发,即使TextBox有焦点。 https://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx 要完成答案(编辑) : 正如上面在我对你的问题的评论(以及其他贡献者)中所述:在任何给定的时间只有一个控件可以关注。 所以,你原来的问 ... -
$(function() { var txt = $("#myTextbox"); var func = function() { txt.val(txt.val().replace(/\s/g, '')); } txt.keyup(func).blur(func); }); 您必须另外处理blur事件,因为用户可以使用上下文菜单进行粘贴;) $(function() { var txt = $("#myTextbox"); var func = function() { ...
-
除了SDX2000的答案之外,请查看关于KeyDown事件的MSDN文章 。 它还引用在KeyDown事件之后触发的KeyPressed事件,我认为它更适合您想要执行的操作。 引用MSDN: KeyPressEventArgs指定用户按下某个键时组成的字符。 例如,当用户按下SHIFT + K时,KeyChar属性返回一个大写的K. private void YourEventHandler(object Sender, KeyPressEventArgs Args) { if(!searchTex ...
-
VB的textbox.focus()问题(VB textbox.focus() problem)[2022-03-05]
尝试更改tabindex属性。 在webforms中,请参阅http://www.w3schools.com/aspnet/prop_webcontrol_standard_tabindex.asp 在设计视图打开时,在winforms视图 - > Tab顺序中 如果这不起作用,请尝试在TextBox上调用Select()方法。 Try changing the tabindex property. in webforms, see http://www.w3schools.com/aspnet/prop_ ... -
TextBox神秘失去焦点(TextBox mysteriously losing focus)[2022-10-30]
它会这样做。 在按键时,您会触发异步回发,这就是导致您失去焦点的原因。 你必须使用javascript,并使用 Sys.Application.add_endRequest(function(sender, e) { }) 听取请求的结束并重新关注焦点。 我明白你要做什么,我强烈建议你使用网络服务或信号器来做你想做的事情。 你不会得到你想要的能力或表现。 更新面板在回发时会将焦点移开,因此用户不能只是继续键入。 更新面板在某种程度上是限制性的。 It's going to do that. On key ... -
TextBox行为是否正确(Is TextBox behavior correct)[2022-03-20]
如果你想阻止任何输入,你可以(事实上, 应该 )也设置ReadOnly = true而不是监听KeyDown事件。 如果你想有选择地防止击键,那么听KeyDown和设置e.Handled是唯一的方法。 但是,有选择地防止击键对于可用性是不利的; 不要这样做。 而是使用文本框控件的Validating事件来验证用户输入。 If you want to prevent any input you can (in fact, should) also set ReadOnly = true instead of ... -
TextBoxBase.SelectionStart textBox1.Focus(); textBox1.SelectionStart = textBox1.Text.Length; TextBoxBase.SelectionStart textBox1.Focus(); textBox1.SelectionStart = textBox1.Text.Length;
-
听起来像你的一个脚本正在设置一些专注于加载的东西。 在