如何使用jQuery选择属性标签内的元素ID? [英] How to select Element Id inside attribute tag with jQuery?

查看:141
本文介绍了如何使用jQuery选择属性标签内的元素ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查输出和->问题.. 我是Bootstrap和JQuery编程的新手.我想知道如何选择另一个元素的属性内的输入元素的"id".
我正在使用bootstrap进行弹出.当我点击<a></a>链接时,它会产生一个弹出窗口,但我想在 data-content 元素(即

Check Output and -->question. . I am new to programming in Bootstrap and JQuery. I want to know How to select the "id" of input element which is inside the attribute of another element.
I am using bootstrap for popover. when I click on <a></a> link it produce a popover but I want to get the element id inside data-content element i.e

我从中选择锚点并显示弹出窗口的文件.现在要在锚标记内但在锚元素的 data-content 属性内选择id

This File from where i am selecting anchor and displaying popover. Now want to select the id inside the anchor tag but within data-content attribute of anchor element

        $("a").popover(
            
        {
             delay:1000,
             html: true,

               

        })

这是Html标记,其中我在锚标记中插入了bootstrap属性,并在bootstrap data-content 中插入了html元素,并希望在的data-content属性中选择该输入元素的ID. anchr标签.

This is Html Tag in which inside anchor tag i inserted bootstrap attribute and inside bootstrap data-content i inserted the html elemnt and want to select the ID of that input element inside data-content attribute of anchr tag.

该怎么做?

<a href="#" data-toggle="popover" title="Username:"  data-content='<input id="Uname" data-toggle="popover" data-trigger="focus" data-content="You are Successfull!!!!" type="text"/><input id="btnEdit" type="button" value="Edit" />'></a>

该怎么做?
任何人都可以建议

How to do it?
Anyone Can Suggest

推荐答案

尝试为data-content元素实例化一个新的jquery对象,如下所示:

Try instantiating a new jquery object for the data-content element, like so:

    $('a').on('click', function () {
        var content = $(this).data('content');
        var input = $(content);
        window.alert(input.attr('id'));
    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a href="#" data-toggle="popover" title="Username:"  data-content='<input id="Uname" data-toggle="popover" data-trigger="focus" data-content="You are Successfull!!!!" type="text"/><input id="btnEdit" type="button" value="Edit" />'>Click me!</a>

使用活动代码段进行了更新.

Updated with active snippet.

这篇关于如何使用jQuery选择属性标签内的元素ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆