Voglio analizzare una stringa su un oggetto nodo. La seguente funzione dovrebbe fare qualcosa di simile:JQuery converte stringa in oggetto nodo
Voglio ottenere un elemento di input, incorporato in un tag Li, in cui l'elemento di input può essere un pulsante di opzione o semplicemente un pulsante. Se il tipo è dato come radio, è necessario aggiungere un'etichetta.
Purtroppo, la parte:
inputElement = $.parseHTML(this.getFullHtmlTextOf(inputElement) + labelElement);
fallisce.
this.getKeyValAsInputInLiWithType = function (key, val, isArgument, type, isChecked) {
var liElement, inputElement, labelElement;
liElement = document.createElement('li');
liElement.setAttribute('id', 'li_' + key);
inputElement = document.createElement('input');
inputElement.setAttribute('id', key);
inputElement.setAttribute('type', type);
inputElement.setAttribute('value', val);
inputElement.setAttribute('data-dismiss', 'modal');
// additional attributes for a button
if (type === 'button') {
inputElement.setAttribute('class', 'button button-block btn btn-primary btn-default btn-discussion');
}
// additional attributes for a radio button
if (type === 'radio') {
if (isChecked) {
inputElement.setAttribute('checked', '');
}
// adding label for the value
labelElement = '\<label for="' + key + '"\>' + val + '\</label\>';
inputElement = $.parseHTML(this.getFullHtmlTextOf(inputElement) + labelElement);
}
if (key === addStatementButtonId) {
inputElement.setAttribute('onclick', "$('#'+addArgumentContainerId).show();$('#'+addStatementButtonId).disable = true;");
} else if (type === 'button') {
if (isArgument) {
inputElement.setAttribute('onclick', "new InteractionHandler().argumentButtonWasClicked(this.id, this.value);");
} else {
inputElement.setAttribute('onclick', "new InteractionHandler().positionButtonWasClicked(this.id, this.value);");
}
}
alert(this.getFullHtmlTextOf(inputElement));
liElement.appendChild(inputElement);
return liElement;
};
Cordiali saluti,
Tobias
E la tua domanda è? – thodic
Si prega di fare riferimento al link seguente per analizzare la stringa sull'oggetto nodo http://api.jquery.com/jquery.parsehtml/ –
Il problema è che l'ultima istruzione, dove liElement accoda il figlio, non riesce con "Impossibile eseguire" appendChild 'on' Node ': il parametro 1 non è di tipo' Node '. " –