使用jquery没有触发点击事件附加到div中的Html单选按钮类型标记 [英] Html radio button type tags appended into div using jquery no firing click event

查看:69
本文介绍了使用jquery没有触发点击事件附加到div中的Html单选按钮类型标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery

I am using jquery

3.3.1.min.js

。在我的项目中,我在运行时从Javascript部分创建HTML单选按钮并将其附加到div标签中。我正在创建的HTML标记附带了点击事件。问题是这个点击事件不会被触发。这是我的代码:



Javascript部分:



$(文件).ready(function() {

调试器;

$('。UserType')。click(function(){

调试器;

alert(a);

});

PPP();

});



函数PPP(){

var html ='< label class =btn btn-primary>< input class =UserTypeid =UserType name =UserTypetype =radiovalue =1>个人< / label> < label class =btn btn-primary>< input class =UserTypeid =UserTypename =UserTypetype =radiovalue =2> Admin< / label> < label class =btn btn-primary>< input class =UserTypeid =UserTypename =UserTypetype =radiovalue =3> Agent< / label> < label class =btn btn-primary>< input class =UserTypeid =UserTypename =UserTypetype =radiovalue =4> SubAgent< / label>'

$(#divUserType)。append(html);

}



HTML部分:



< body>

< form id =form1runat =server>

< div id =divUserType>



< / div>

< / form>

< / body>



在检查时,我发现元素已创建。但是当我查看页面源时,附加的HTML标签不存在。



我尝试过:



尝试为点击创建突兀的代码,但这也没有用。

. In my project, I am creating HTML radio button at runtime from Javascript section and appending it in div tag. HTML tag I am creating has click event attached with it. The problem is this click event does not get fired. Here is my code:

Javascript Section:

$(document).ready(function () {
debugger;
$('.UserType').click(function () {
debugger;
alert("a");
});
PPP();
});

function PPP() {
var html = '<label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="1">Individual</label> <label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="2">Admin</label> <label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="3">Agent</label> <label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="4">SubAgent</label>'
$("#divUserType").append(html);
}

HTML Section:

<body>
<form id="form1" runat="server">
<div id="divUserType">

</div>
</form>
</body>

While inspecting, I found out that element is created. But when I did view page source, appended HTML tags does not exist.

What I have tried:

Tried creating obtrusive code for click but this too did not work.

推荐答案

(document).ready(function(){

调试器;
(document).ready(function () {
debugger;


('。UserType')。click(function(){

debugger;

alert(a);

});

PPP();

});



功能PPP(){

var html ='< label class =btn btn-primary>< input class =UserType id =UserTypename =UserTypetype =radiovalue =1> Individual< / label> < label class =btn btn-primary>< input class =UserTypeid =UserTypename =UserTypetype =radiovalue =2> Admin< / label> < label class =btn btn-primary>< input class =UserTypeid =UserTypename =UserTypetype =radiovalue =3> Agent< / label> < label class =btn btn-primary>< input class =UserTypeid =UserTypename =UserTypetype =radiovalue =4> SubAgent< / label>'
('.UserType').click(function () {
debugger;
alert("a");
});
PPP();
});

function PPP() {
var html = '<label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="1">Individual</label> <label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="2">Admin</label> <label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="3">Agent</label> <label class="btn btn-primary"><input class="UserType" id="UserType" name="UserType" type="radio" value="4">SubAgent</label>'


(#divUserType)。append(html);

}



HTML部分:



< body>

< form id =form1runat =server>

< div id =divUserType>



< / div>

< / form>

< / body>



在检查时,我发现元素已创建。但是当我查看页面源时,附加的HTML标签不存在。



我尝试过:



尝试为点击创建突兀的代码,但这也不起作用。
("#divUserType").append(html);
}

HTML Section:

<body>
<form id="form1" runat="server">
<div id="divUserType">

</div>
</form>
</body>

While inspecting, I found out that element is created. But when I did view page source, appended HTML tags does not exist.

What I have tried:

Tried creating obtrusive code for click but this too did not work.


这篇关于使用jquery没有触发点击事件附加到div中的Html单选按钮类型标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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