[英]How do I replicate onclick button results when a user clicks a DIV?
I also have a text box where the user can enter a name and the objects associated to that user are returned via a query and displayed on the html page using 我还有一个文本框,用户可以在其中输入名称,并通过查询返回与该用户关联的对象,并使用
<div id="FriendsStuff"></div>
The code for the search function is 搜索功能的代码是
$(document).ready(function () {
$(document).on('click', '.username, #find_button', function (event) {
//debugger;
event.preventDefault();
friendName = $(this).is("button") ? null : $(this).text();
friendFeed(friendName);
});
});
I also have a div that lists the users (Instead of having to search for them) on the html page 我还有一个div,它在html页面上列出了用户(而不是搜索他们)
<div id="container"></div>
Populated by this: 由此填充:
$('#container').append("<img class='images' src='" + imageURLs[j] + "'/>");
$('#container').append("<div class='username'>'" + Username[j] + "'</div>");
What I want the user to do is click on the name that is displayed on the page and replicate the same action as what happens if the user clicks the "find" button. 我希望用户执行的操作是单击页面上显示的名称,并复制与用户单击“查找”按钮时发生的操作相同的操作。 Basically to return the associated results back to the page.
基本上是将相关结果返回到页面。
The example page is here, http://www.kudosoo.com/friendslist.html so for example the user clicks "dave" and the result is the same as if they'd entered "dave" into the text box and clicked "find" 示例页面位于http://www.kudosoo.com/friendslist.html,因此,例如,用户单击“ dave”,结果与在文本框中输入“ dave”并单击“找”
How can I achieve this? 我该如何实现? Do I reference the container div within the onclick function?
我是否在onclick函数中引用了容器div?
I don't see a Dave at that link and I'm having a hard time following your question but I believe you're looking for .val
and .trigger
. 我在该链接上没有看到戴夫,并且很难回答您的问题,但我相信您正在寻找
.val
和.trigger
。
This would set the value of the input. 这将设置输入的值。
$('#friendsearch').val('Dave');
and then you trigger the click. 然后触发点击。
$('.btn-login').trigger('click');
You should consider putting these elements into a form. 您应该考虑将这些元素放入表单中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.