我想知道如何单击另一个元素的属性" data-content"的输入元素的ID" uname"。我正在使用Bootstrap进行弹出。当我单击链接时,它会产生一个弹出窗口,但我想单击元素ID" uname"内部data-content属性
$('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>
应触发popover shown.bs.popover
事件!单击"单击此处"时,您将获得弹出,然后单击弹出的输入元素,可以获取警报!
这是片段!
$('[data-toggle="popover"]').popover({html:true});
$('[data-toggle="popover"]').on('shown.bs.popover', function () {
$('#Uname').click(function(){
alert($(this).data('content'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.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>
希望有帮助!