var askQuitHTMLMessage =
"<p><strong>Waar moet rekening mee worden gehouden bij het inplannen?</strong></p>" +
"<p><strong>Vul de volgende gegevens in om het resultaat te bepalen:</strong></p>" +
"<p><input class='inplan_var' data='ingeplande_uren' type='checkbox' name='medewerkers' id='aantmdw'><strong>	 Aantal uren resource</strong></input></p>" +
"<p><input class='inplan_var' data='ervaring' type='checkbox' name='medewerkers' id='ervaring'><strong>	 Ervaring</strong></input></form></p>" +
"<p><input class='inplan_var' data='expertise' type='checkbox' name='medewerkers' id='expertise'><strong>	 Expertise</strong></input></form></p>" +
"<p><input class='inplan_var' data='etc' type='checkbox' name='medewerkers' id='etc'><strong>	 Etcetera</strong></input></form></p>";
如何在javascript变量中获取其中一种输入类型的id?
答案 0 :(得分:1)
这是一个解决方案,可以为您提供一系列ID
使用代码:https://jsbin.com/vejumo/edit?js,console
var askQuitHTMLMessage = "...." // The string in the question
var tmpDiv = document.createElement('div');
tmpDiv.innerHTML = askQuitHTMLMessage;
var inputs = tmpDiv.querySelectorAll('input');
var ids = [];
inputs.forEach(function(input) {ids.push(input.id)})
console.log(ids);
答案 1 :(得分:0)
这应该适合你
$('input',$(askQuitHTMLMessage))。each(function(){console.log(“id:”+ $(this).attr('id'))})