Ich möchte eine bestimmte Anzahl von span-Elemente in Eingabefelder drehen, wenn ich auf die Schaltfläche Bearbeiten und zurück, um zu spannen, wenn ich auf ein anderes klicke, aber ich habe einige Probleme :Drehen eines Bereichs in ein Eingabefeld mit jquery
Hier ist meine Geige:
Und mein Code:
HTML:
<span id="1">hedh</span>
<br />
<span id="2">2222eh3222222</span>
<br />
<span id="3">333333eh33333</span>
<br />
<span id="4">44444eher44444</span>
<br />
<span id="5">555555edgt5555</span>
<br />
<button id="edit_properties">Edit</button>
<button id="unedit_properties">Save</button>
JavaScript:
var switchToInput = function(id_value) {
var $input = $("<input>", {
val: $(this).text(),
type: "text"
});
$input.attr("ID", id_value);
$(this).replaceWith($input);
$input.select();
};
var switchToSpan = function(id_value) {
var $span = $("<span>", {
text: $(this).val()
});
$span.attr("ID", id_value);
$(this).replaceWith($span);
$span.on("click", switchToInput);
}
$("#edit_properties").on("click", function() {
switchToInput(1);
switchToInput(2);
switchToInput(3);
switchToInput(4);
switchToInput(5);
});
$("#unedit_properties").on("click", function() {
switchToSpan(1);
switchToSpan(2);
switchToSpan(3);
switchToSpan(4);
switchToSpan(5);
});
Was sind die Themen? –
@RoryMcCrossan es funktioniert nicht. Ich würde sagen, das ist das wichtigste – laker001
Super hilfreich. Danke –