简体   繁体   English

用户单击DIV时如何复制onclick按钮结果?

[英]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.

相关问题 当用户单击按钮时如何防止作弊 - How do I prevent cheating when user clicks a button 当用户将其单击到另一个单词时,如何创建一个可以更改单词的OnClick函数? - How do I make an OnClick function that will change a word when a user clicks it to another word? 当用户在div之外单击时,如何使用jQuery this和class影响div - How do I use jQuery this and class to affect a div when the user clicks outside the div 用户在父div中单击时单击按钮 - click button when user clicks in parent div 当用户单击菜单按钮时,如何弹出菜单? - How do I make a menu pop up when the user clicks the menu button? 当用户单击按钮时,如何保存可重复使用的React组件? - How do i make my reusable react component saves when the user clicks button? 当用户单击其他按钮时,如何取消选择整个单选按钮组? - How do I deselect a whole group of radio buttons when a user clicks on some other button? 当用户点击按钮时,如何让html运行javascript函数? - How do I make html run a javascript function when a user clicks a button? 当用户单击按钮时,如何 select 数组中的下一个项目? - How do I select the next item in an array when a user clicks on a button? 用户单击提交按钮时如何获取显示的时间 - How do I fetch displayed time when user clicks submit button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM