我正在动态生成 iframe
及其 id
。
现在我要查找 Id
是否已经存在。
我的代码将是,
function createIframe(intxnId){
alert("Id is : "+"$('#"+intxnId+"')");
if($("'#ch"+intxnId+"'").length == 0){
alert("Creating the new Iframe intxnId is: " +intxnId);
var iframe = "<iframe id='ch"+intxnId+"' src='" + contexPath + "/HeartChat.html?intxnId="+intxnId+"' class='iframeSize'></iframe>";
alert("iFrame Details : "+iframe);
$("#chatMessageArea").find("#messageArea").html(iframe);
}else{
alert("ID is already present !");
}
}
我对动态 Id 的警告是,
但我得到的错误是,
非常感谢好的答案!
最佳答案
您的 jQuery 选择器无效,由于某种原因它被单引号括起来。更改为:
if($("#ch"+intxnId).length == 0){
当前您的选择器评估为:
$("'#chXYZ'") // wrong, it should evaluate to $("#chXYZ")
此外,您的问题中没有可以产生显示的警报的代码。
关于javascript - jQuery - 发现 id 存在于 iframe 条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17278844/